Reputation: 24304
I am trying to do schema migration in PostgreSQL via Alembic.
Following this question Undo last alembic migration
I have 2 migrations with:
revision = '0eb4bd9decb0',down_revision = None
--and
revision = 'bf34bf428845' ,down_revision = '0eb4bd9decb0'
So I am successfully run migrations from both migration files by:
alembic upgrade 0eb4bd9decb0
alembic upgrade bf34bf428845
Now I have a problem in Downgrading these migration i.e I want to downgrade migration with revision= 'bf34bf428845'
so I write:
alembic downgrade bf34bf428845
But It is not Working and not showing any error
Output of above code:
(migration) C:\xampp\htdocs\dbmigration python\migration\db>alembic downgrade bf34bf428845
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
but if I run this code:
alembic downgrade -1
It is working as expected as per by Undo last Alembic migration
My question:
How can I downgrade alembic migration by revision id?
Upvotes: 0
Views: 3311
Reputation: 123399
When you run
alembic upgrade 0eb4bd9decb0
alembic upgrade bf34bf428845
which, by the way, is the same as just
alembic upgrade bf34bf428845
your database will be at revision bf34bf428845. Then if you run
alembic downgrade bf34bf428845
it will have no effect because the database is already at revision bf34bf428845.
If you want to undo the changes that brought you to revision bf34bf428845 you need to downgrade to the revision before bf34bf428845, i.e.,
alembic downgrade bf34bf428845-1
or
alembic downgrade 0eb4bd9decb0
Upvotes: 1