Flask-Blog-Tutorial icon indicating copy to clipboard operation
Flask-Blog-Tutorial copied to clipboard

Error in Tutorial 2

Open Asaduddin18 opened this issue 3 years ago • 2 comments

I am getting this error in tutorial 2 and I am unable to create the database to store the user sign-up info

from flask_sqlalchemy import SQLAlchemy from .extension import SQLAlchemy from .model import _QueryProperty class DefaultMeta(BindMetaMixin, NameMetaMixin, sa.orm.DeclarativeMeta): AttributeError: module 'sqlalchemy.orm' has no attribute 'DeclarativeMeta'

Asaduddin18 avatar Oct 05 '22 13:10 Asaduddin18

Flask-SQLAlchemy 3 no longer accepts an app argument to methods like create_all. Instead, it always requires an active Flask application context. There is no need for the create_database function. So instead write this in the create app function

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

i hope this solves your problem

prranavv avatar Dec 26 '22 15:12 prranavv

I had a similar error giving me sqlite3.OperationalError: no such table: user. This fix worked though. Thanks @prranavv!

ryzinn18 avatar Feb 27 '23 16:02 ryzinn18