Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLAlchemy.create_all() got an unexpected keyword argument 'app' #111

Open
SwayamBadhe opened this issue Mar 6, 2023 · 2 comments
Open

Comments

@SwayamBadhe
Copy link

image

SQLAlchemy.create_all() got an unexpected keyword argument 'app'

`from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from os import path

db = SQLAlchemy()
DB_NAME = 'database.db'

def create_app():
app = Flask(name)
app.config['SECRET_KEY'] = 'kjsdhfkjashfkh'
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'
db.init_app(app)

from .views import views
from .auth import auth

app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')

from .models import User, Note

create_database(app)

return app

def create_database(app):
if not path.exists('website/' + DB_NAME):
db.create_all(app=app)
print('Created Database!')`

@AusafMo
Copy link

AusafMo commented Mar 7, 2023

You no longer have to manually check if path.exists() in flask, instead do this

with app.app_context():
db.create_all()

this checks it for you, I believe it's already updated in the git, auth.py file though.

@antaeusw
Copy link

This is explained well in this StackOverflow discussion: https://stackoverflow.com/questions/73968584/flask-sqlalchemy-db-create-all-got-an-unexpected-keyword-argument-app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants