Flask-Migrate icon indicating copy to clipboard operation
Flask-Migrate copied to clipboard

`db migrate` success, but `db upgrade` fail, what can i do next?

Open meimeitou opened this issue 4 years ago • 3 comments

run

flask db migrate
# return success

# then
flask db upgrade
# return failed
# o my models file define error,  so i corrected it.
# then run
flask db migrate
# return:   ERROR [flask_migrate] Error: Target database is not up to date.

What do I do in this case next?

i fix models file, but can’t migrate or upgrade again.

one way is delete all file, and db init again, but this is not what I want.

meimeitou avatar Oct 28 '21 10:10 meimeitou

Delete the bad migration file (the one that failed to upgrade), then you should be able to run flask db migrate again.

miguelgrinberg avatar Oct 28 '21 10:10 miguelgrinberg

Delete the bad migration file (the one that failed to upgrade), then you should be able to run flask db migrate again.

flask db history, have the migrate version

so i should delete migrations file in project and delete version history in db ?

meimeitou avatar Oct 28 '21 10:10 meimeitou

You should delete the migration file that fails to upgrade. Just that one file. It is going to be listed as the latest migration script in the history report. If you run flask db current you will have a different migration as the current migration installed in your database (the previous one), so this failing migration script is not referenced by your database and can be deleted and recreated after you fix the problem.

miguelgrinberg avatar Oct 28 '21 11:10 miguelgrinberg