Flask-Migrate No Changes Detected to Schema on first migration
I encountered this problem and solved it by importing my models at env.py
in the migrations folder right after the following comments
# add your model's MetaData object here# for 'autogenerate' support# from myapp import mymodel# target_metadata = mymodel.Base.metadatafrom app.models import Student, Tutor
Pls make sure that you already import your models (Tutor, Student, ...) before your migrate.init_app(app, db)
This is how I solved the problem in my case:
- Import the
Migrate
model:from flask_migrate import Migrate
- Initiate
Migrate
class:migrate = Migrate(app, db)
- Comment
db.create_all()
- Drop your database now =>
DROP DATABASE db_name;
- Create it again =>
CREATE DATABSE db_name OWNER owner_name;
- Export you flask entry file =>
export FLASK_APP=name_app.py
- Run
flask db migrate
Note: The 6th step should be used in case you get this error:
Error: Could not locate a Flask application
Hope this will help someone.