Error when autogenerate migration scripts with alembic

3,185 views
Skip to first unread message

Ons

unread,
Nov 17, 2014, 10:20:12 AM11/17/14
to sqlalchem...@googlegroups.com
Hi,

I want to use alembic to auto-generate migrations scripts for my postgres db. When i tried:
#alembic upgrade and  alembic downgrade both worked properly, but when i modified my models and tried
#alembic revision --autogenerate it raises this error :

INFO  [alembic.migration] Context impl PostgresqlImpl.
INFO  [alembic.migration] Will assume transactional DDL.
ERROR [alembic.util] Target database is not up to date.
  FAILED: Target database is not up to date.

In env.py, i imported my models and set target_metadata to myModels.Base.metadata.

Anyone has an idea on how to solve this issue or what is causing the error above ?

Thanks.

Michael Bayer

unread,
Nov 17, 2014, 10:27:37 AM11/17/14
to sqlalchem...@googlegroups.com
when you run alembic revision with —autogenerate, the database has to be up-to-date. This means that the most “head” version that is in your versions/ directory must be the same version that is in your database in the “alembic_version” table.

So this means one of two things:

1. you need to run alembic upgrade

2. there is a version file in your versions/ directory that you don’t actually want, like you ran alembic revision already, it created a file, and you don’t actually want that file, you’d delete it first.

you can run “alembic history” to see all the versions that are in your versions/ directory in order.


Ons

unread,
Nov 17, 2014, 10:38:47 AM11/17/14
to sqlalchem...@googlegroups.com
It worked. Thank you for your great explanation.
Reply all
Reply to author
Forward
0 new messages