Skip to content Skip to sidebar Skip to footer

Can't Migrate Or Upgrade Database With Flask-migrate (alembic)

I've been using Flask-Migrate (Alembic) for updating my database. I updated my models.py file however I made an error. I ran a migration and went to upgrade the database, however I

Solution 1:

Alembic stores the db version in a table it creates called alembic_version. This table contains a single field and row alembic_version.version_num. Make sure the value for this matches the filename of the most recent file in migrations/version. This version number is also contained inside the revision file in the revision variable that generally shows up on line 26 of the file. Make sure it matches the db version.

Another option is to simply drop the db and recreate it using alembic. If this is a development environment, where the data is not important, that would be my recommendation.

Solution 2:

I feel like the accepted answer is a little over-complicated. I had this same issue and the way that I solved it was to simply delete the migration that contained the coding errors. You don't need it anyways since, again, it was coded incorrectly. Find the latest migration in the migrations/versions folder, delete it, then run your migration again and upgrade. You don't need to delete the data in your database just to migrate it.

Solution 3:

alembic.util.CommandError: Target database is not up to date.

Could you try the following steps?

python manage.py db stamp head
python manage.py db migrate
python manage.py db upgrade

'stamp' the revision table with the given revision; don't run any migrations

Solution 4:

The first step is remove the latest migrate version created, then you should use these commands:

 flask db stamp head
 flask db migrate -m "newMigration"
 flask db upgrade

Post a Comment for "Can't Migrate Or Upgrade Database With Flask-migrate (alembic)"