Flask-Web-App-Tutorial
Flask-Web-App-Tutorial copied to clipboard
TypeError: 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'] = 'hjshjhdjah kjshkjdhjs'
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!')
I am getting the same issue and I am using the original source code with no modifications...
This is because flask-sqlalchemy update in 3.0 look up here https://flask-sqlalchemy.palletsprojects.com/en/3.0.x/quickstart/#create-the-tables
update your code to this
def create_database(app):
if not path.exists('website/' + DB_NAME):
with app.app_context():
db.create_all()
print('Created Database!')
your database will created in folder \instance\database.db
This is because flask-sqlalchemy update in 3.0 look up here https://flask-sqlalchemy.palletsprojects.com/en/3.0.x/quickstart/#create-the-tables
update your code to this
def create_database(app): if not path.exists('website/' + DB_NAME): with app.app_context(): db.create_all() print('Created Database!')
your database will created in folder \instance\database.db
Thank you so much, was getting very confused myself.
thanks dude, u saved my life... XD
thanks for sharing. My db is created in a folder called: instance folder anyone kow why and how to revert it to the website folder?
Thank you for the help.. Solved my problem