0

I am trying to get my database up and running for flask and there is an issue when I type flask db migrate -m "users table". It keeps giving me an error that says this:

ERROR [root] Error: Can't locate revision identified by '1cccee45d6e7'

I tried deleting the migration file, then rerunning the code to start the database in cmd:

(venv) $ flask db init 

Which worked fine and created a new migration file in the flask app directory. Then I did:

(venv) $ flask db migrate -m "users table"

and here is where I get the problem again:

(venv) C:\sitesfolder\microblog\app>flask db migrate
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 '1cccee45d6e7'

I'm following this tutorial.

davidism
  • 121,510
  • 29
  • 395
  • 339
Connor Smith
  • 1
  • 1
  • 2

3 Answers3

2

You can simply resolve the issue using the following commands.

flask db revision --rev-id 1cccee45d6e7
flask db migrate
flask db upgrade
Venus713
  • 1,441
  • 12
  • 24
0

Disclaimer: the solution below is not perfect for every situation.

Typically that would mean that your database is out of sync with your migration files. This can happen when a revision file was deleted after the migration was applied. Check your database, it should contain a table that holds the last migration applied. If there is no file for that revision you will get the Can't locate revision... error.

If you are only just starting with your migrations, one possible solution would be to:

  • Delete all your tables and migration files
  • Re-initialise your migrations
  • Generate a new migration file from your models
  • Apply the migrations

This however can have some undesired consequences if you already have some revisions committed to source control and applied to other deployments, like other developers machines or servers. Basically all the environments will need to be re-initialised this way, but, again, that might not mater if you are just starting afresh.

dmitrybelyakov
  • 3,709
  • 2
  • 22
  • 26
0

Simply you can change alembic_version in database according to you version folder in migrations. Then it works for me.

madogan
  • 605
  • 7
  • 11