[SOLVED] Flask db migrate: Target database is not up to date.

Sometimes it can be to work on the same Flask (Documentation Here) project from several machines each holding a test database, when working with Flask Migrate this might generate some inconsistencies. Indeed, more than once I've been facing the following error while performing "flask db migrate; flask db upgrade;" commands:

Target database is not up to date

In order to solve this problem there is the need to align the version of the database with the migration table data:

First, we might want to have a look to the actual heads:

flask db heads

this command shows the currently available heads in the revision script directory

then we might check  the current revision of the database:

flask db current

In case of inconsistencies the outputs of the command above should be different.

Then, in order to set up and align the revisions:

flask db stamp heads

Sets the revision in the database to the one given as an argument, without performing any migrations (heads = the latest).

Finally, in order to migrate I usually perform the following commands:

flask db migrate;
flask db upgrade;

the migrate command could be avoided.

We've learn't how to solve the problem with Flask-Migrate error when the target database is not up to date.

Show Comments