Search code examples
pythonsqlalchemyflaskflask-sqlalchemyalembic

Detect changes to models.py using Alembic with Flask-SQLAlchemy in Flask Application


I'm trying to use Alembic with Flask-SQLAlchemy and Flask. Here is my application directory structure

/myapp
app.py
     /module1
     __init__.py
     views.py
          /module2
          __init__.py
          models.py
          alembic.ini
          /migrations
               env.py

I have a couple of classes in models.py. What I want is a method such that alembic can check for the changes (like any new added classes in models.py) and generate a version file (upon running a command) so that it reflects in the upgrade() function.

How do i achieve this?. I am sure this should be possible but not getting how to accomplish this!

PS: If you need any extra information please let me know.


Solution

  • alembic revision --autogenerate -m "<message_here>"
    

    and

    alembic upgrade head
    

    are the commands that i needed!