Nov-30-2020, 02:51 PM
Good day,
I am trying to make migration via Flask/Migrate/SQLAlchemy and getting the following error:
What could be the reason?
My run.py file is inside project folder. run.py contains code:
Inside project folder there is flaskblog folder. Then __init__ file there contains code:
So in terminal inside project folder I was not sure how to set
Instead I wrote command
worked, but
returns the error I have mentioned.
I am trying to make migration via Flask/Migrate/SQLAlchemy and getting the following error:
1 2 |
'The sqlalchemy extension was not registered to the current ' \ AssertionError: The sqlalchemy extension was not registered to the current application. Please make sure to call init_app() first. |
My run.py file is inside project folder. run.py contains code:
1 2 3 4 5 6 7 |
from flaskblog import app, db from flask import Flask db.init_app(app) if __name__ = = '__main__' : app.run(debug = True , port = 5002 ) socketio.run(app) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate #... other packages.. basedir = os.path.abspath(os.path.dirname(__file__)) app = Flask(__name__) app.config[ 'SECRET_KEY' ] = 'dfjkfjkfdjklfjlkfdlfdlkj' #... db = SQLAlchemy(metadata = MetaData(naming_convention = naming_convention)) migrate = Migrate(app, db) migrate.init_app(app, db, render_as_batch = True ) #... |
1 |
FLASK_APP = WhatToTypeHere?" |
1 |
export FLASK_APP = flaskblog |
1 |
flask db init |
1 |
flask db migrate |
