Target database is not up to date

前端 未结 11 1158
别那么骄傲
别那么骄傲 2020-12-12 16:54

I\'d like to make a migration for a Flask app. I am using Alembic.

However, I receive the following error.

T         


        
相关标签:
11条回答
  • 2020-12-12 17:17

    After creating a migration, either manually or as --autogenerate, you must apply it with alembic upgrade head. If you used db.create_all() from a shell, you can use alembic stamp head to indicate that the current state of the database represents the application of all migrations.

    0 讨论(0)
  • 2020-12-12 17:18

    I had to delete some of my migration files for some reason. Not sure why. But that fixed the problem, kind of.

    One issue is that the database ends up getting updated properly, with all the new tables, etc, but the migration files themselves don't show any changes when I use automigrate.

    If someone has a better solution, please let me know, as right now my solution is kind of hacky.

    0 讨论(0)
  • 2020-12-12 17:18

    This can also happen if you, like myself, have just started a new project and you are using in-memory SQLite database (sqlite:///:memory:). If you apply a migration on such a database, obviously the next time you want to say auto-generate a revision, the database will still be in its original state (empty), so alembic will be complaining that the target database is not up to date. The solution is to switch to a persisted database.

    0 讨论(0)
  • 2020-12-12 17:20

    To fix this error, delete the latest migration file ( a python file) then try to perform a migration afresh.

    0 讨论(0)
  • 2020-12-12 17:22

    My stuation is like this question, When I execute "./manage.py db migrate -m 'Add relationship'", the error occused like this " alembic.util.exc.CommandError: Target database is not up to date."

    So I checked the status of my migrate:

    (venv) ]#./manage.py db heads
    d996b44eca57 (head)
    (venv) ]#./manage.py db current
    INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
    INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
    715f79abbd75
    

    and found that the heads and the current are different!

    I fixed it by doing this steps:

    (venv)]#./manage.py db stamp heads
    INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
    INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
    INFO  [alembic.runtime.migration] Running stamp_revision 715f79abbd75 -> d996b44eca57
    

    And now the current is same to the head

    (venv) ]#./manage.py db current
    INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
    INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
    d996b44eca57 (head)
    

    And now I can do the migrate again.

    0 讨论(0)
  • 2020-12-12 17:22

    To solve this, I drop(delete) the tables in migration and run these commands

    flask db migrate
    

    and

    flask db upgrade
    
    0 讨论(0)
提交回复
热议问题