Flask-Migrate No Changes Detected to Schema on first migration Flask-Migrate No Changes Detected to Schema on first migration flask flask

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:

  1. Import the Migrate model: from flask_migrate import Migrate
  2. Initiate Migrate class: migrate = Migrate(app, db)
  3. Comment db.create_all()
  4. Drop your database now => DROP DATABASE db_name;
  5. Create it again => CREATE DATABSE db_name OWNER owner_name;
  6. Export you flask entry file => export FLASK_APP=name_app.py
  7. 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.