We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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'
`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!')`
The text was updated successfully, but these errors were encountered:
You no longer have to manually check if path.exists() in flask, instead do this
if path.exists()
with app.app_context(): db.create_all()
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.
Sorry, something went wrong.
This is explained well in this StackOverflow discussion: https://stackoverflow.com/questions/73968584/flask-sqlalchemy-db-create-all-got-an-unexpected-keyword-argument-app
No branches or pull requests
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)
def create_database(app):
if not path.exists('website/' + DB_NAME):
db.create_all(app=app)
print('Created Database!')`
The text was updated successfully, but these errors were encountered: