I am reading (and watching) about Flask-Migrate here: https://realpython.com/blog/python/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/ and here https://www.youtube.com/watch?v=YJibNSI-iaE#t=21
and doing everything from this tutorial:
After you install Flask-Migrate and run
python manage.py db init
python manage.py db migrate
it should detect all tables declared in models.py.
In my case, it detects nothing. And, based on the comments to the tutorial, it's not just my case. So, how do I make this work?
Make sure your model is imported by your app. In most cases your views.py
should do that. But you can also import it directly from your app.py
.
Be sure that you're importing your models the same way throughout your application.
For example, I was using the following in my __init__.py
:
from .models import *
And the following in my manage.py
:
from databases import models
Because these have diff namespaces, flask_manager thinks there are duplicated tables. (Note, I found this solution in the following github issue / thread.)
Fix and all will be well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With