Reset Alembic after deleting migration folder

Viewed 18102

I accidentally deleted my migrations folder. So I ran flask db init, and everything ran smoothly. But when I ran flask db migrate, it gave me this error:

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [root] Error: Can't locate revision identified by '470572fac7a1'

From what I understand, it's looking for my other migration folder which is long gone. How can I solve this?

5 Answers

Delete that particular record in the table alembic_version that's in your database. There's only one varchar column called version_num, so this expression should work:

delete from alembic_version where version_num='470572fac7a1';

Delete the /migrations directory and rename/replicate your applications database. Then start from scratch.

flask db init
flask db migrate
flask db upgrade

Now repopulate your new empty database with data from your backup.

You must delete alembic_version table in your database.

Connect to your database, and execute:

DROP TABLE alembic_version;

Please check the following answer for more details about this https://stackoverflow.com/a/32356600

Go to versions/ inside migrations/.

If you do not see the folder versions/ or there is not a revision inside the folder versions/, type the following command to create a revision:

flask db revision

You'll get a revision inside the versions/ folder. Open it and replace the revision id with '470572fac7a1':

revision = "470572fac7a1"

Type flask db migrate again.

Should work.

pull last version from github. And then backup your prod db. Then restore your local db. Delete your alembic table (with cascade).

Open your terminal (with venv) write code below:

rm - rf migrations
python manage.py db init

and open migrations folder. Right click on alembic.ini and choose git>rollback>ok.

python manage.py db migrate
python manage.py db upgrade

or

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