2

I have installed the Flask-Migration and initialised the migration however I would receive the following error when i run python3 manage.py db migrate.

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/alembic/script.py", line 104, in get_revision
raise util.CommandError("No such revision '%s'" % id_)
alembic.util.CommandError: No such revision '38340accc10'

As suggested in Cannot complete Flask-Migration a possible reason would be that I have done an upgrade which generated the above revision '38340accc10', but then deleted whole migrations/ directory and removed all upgrade scripts.

How do I delete the Alembic versions in my database? I have tried recreating the database with db.drop_all() and db.create_all() but the same error appears.

Community
  • 1
  • 1
luishengjie
  • 187
  • 6
  • 15
  • I'm assuming you want to start from scratch. Get rid of any and all existing data that might be in your db. If that's true, there should be a database directory. If you delete that and start over by issuing the alembic database init command you should be fine. – franklin Mar 05 '16 at 03:56

1 Answers1

2

If you can generate a brand new database, that's the easiest way to address this.

First you need to delete all your tables in your database, or else destroy the database and make a brand new one. Running db.drop_all() is not enough, because this will only delete the tables that are associated with models, it will not delete the Alembic table.

Once you have a completely empty database, you should be able to run ./manage.py db upgrade to bring it back to your latest migration.

If you get errors, then that means that your migration history is broken, maybe because you deleted migration scripts that were in use. In this case, you can wipe out the database, wipe out the migration directory, and then start over with ./manage.py db init, and then ./manage.py db migrate to create an initial migration that matches the current state of your models.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152