Flask Migrate SQLAlchemy – hang

One of the reasons Flask SQLAlchemy hangs during migration.

If the process hangs during migration, when the commands are launched:

flask db init
flask db migrate -m “Description of changes”
flask db upgrade

There may be several reasons:
– the site is not stopped, interfering with making changes to the database;
– the site has an endless loop, like a function to restart something.

This is due to the fact that during the migration, all code is analyzed from the starting point of the launch, going along the chain of imports, calls of functions and methods. And if something prevents it from completing the process, then the migration will freeze.

Error example

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column checks.active does not exist
LINE 1:… AS checks_slug, checks.example AS checks_example, checks.act…

As I wrote above, there is a “run” through the entire code. In the code, we want to add to the table checks new column active, but since there is a section in the site code that calls the table class checks:

check_list = db.sessionquery(Check)all()

And at this moment it does not have a column yet activethen an error occurs.

To fix it, before starting the migration, you need to temporarily comment out the section that refers to this class.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *