Nov-30-2020, 02:51 PM
Good day,
I am trying to make migration via Flask/Migrate/SQLAlchemy and getting the following error:
My run.py file is inside project folder. run.py contains code:
I am trying to make migration via Flask/Migrate/SQLAlchemy and getting the following error:
'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.What could be the reason?
My run.py file is inside project folder. run.py contains code:
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)Inside project folder there is flaskblog folder. Then __init__ file there contains code:
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' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////home/tomas/searvice/flaskblog/site.db' #... db = SQLAlchemy(metadata=MetaData(naming_convention=naming_convention)) migrate = Migrate(app, db) migrate.init_app(app, db, render_as_batch=True) #...So in terminal inside project folder I was not sure how to set
FLASK_APP=WhatToTypeHere?"Instead I wrote command
export FLASK_APP=flaskblog
flask db initworked, but
flask db migratereturns the error I have mentioned.
