Flask migration command is not showing error messages

Issue

We are using Flask with SQLAlchemy and Flask migrate. This was working fine so far but lately it has stopped showing error messages on failures. It just silently fails. I believe this started happening when we upgraded flask-migrate but I’m not 100% sure.

The issue is not that it’s failing, it only fails when there’s a proper reason (multiple head versions, or invalid migration file), but it does not report the error on console.

> flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
> echo $?
1

It works fine and applies migration when there’s no failure:

> flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 34f504777ec2 -> ed96adbb2dd6, empty message
> echo $?
0

Versions:

> flask --version
Python 3.9.15
Flask 1.1.2
Werkzeug 1.0.1
Flask-Migrate = "^2.5.3"

Not sure why the error messages are not showing up.

Solution

This is due to an old bug, it’s not a problem with your application.

The most important thing you need to do is to update the alembic.ini file that is in your migrations directory. You can take the updated version from the GitHub repo.

I think with the above all errors will be printed to the console.

In addition, you may consider upgrading Flask-Migrate to a more recent release, since the version that you are using is about 2.5 years old.

Answered By – Miguel Grinberg

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published