close

[Solved] CommandError: Can’t locate revision identified by ‘…’ when migrating using Flask-Migrate

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error CommandError: Can’t locate revision identified by ‘…’ when migrating using Flask-Migrate in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How CommandError: Can’t locate revision identified by ‘…’ when migrating using Flask-Migrate Error Occurs?

Today I get the following error CommandError: Can’t locate revision identified by ‘…’ when migrating using Flask-Migrate in python.

How To Solve CommandError: Can’t locate revision identified by ‘…’ when migrating using Flask-Migrate Error ?

  1. How To Solve CommandError: Can't locate revision identified by '…' when migrating using Flask-Migrate Error ?

    To Solve CommandError: Can't locate revision identified by '…' when migrating using Flask-Migrate Error In my case I have accidentally deleted the most recent migration file but the alembic version (alembic_version) table refers to the deleted version.

  2. CommandError: Can't locate revision identified by '…' when migrating using Flask-Migrate

    To Solve CommandError: Can't locate revision identified by '…' when migrating using Flask-Migrate Error In my case I have accidentally deleted the most recent migration file but the alembic version (alembic_version) table refers to the deleted version.

Solution 1

In my case I have accidentally deleted the most recent migration file but the alembic version (alembic_version) table refers to the deleted version.

So instead of droping the entire database, you can change the version_num field in the alembic_version table.

Following steps worked for me:

  • Find the head using db history
  • Update the version_num field to the head version.
  • run migrate using db migrate
  • upgrade the database db upgrade

Solution 2

you delete the migration directory but the version has been saved in the database, so you have to delete the version info in the dabase, run

delete from alembic_version;

in mysql shell.

If this is a developing environment or a single app for test, just delete it, Else BACKUP the data in the table.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read