Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset Alembic after deleting migration folder

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?

like image 690
GM Crow Avatar asked Dec 08 '22 13:12

GM Crow


2 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';

like image 189
txtsd Avatar answered Dec 21 '22 14:12

txtsd


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.

like image 24
Mark Kortink Avatar answered Dec 21 '22 14:12

Mark Kortink