Undo last Alembic migration

こ雲淡風輕ζ 提交于 2020-12-29 04:58:17

问题


I created a migration with alembic revision --autogenerate, applied it to my development database with alembic upgrade head, and then realised it wasn't quite what I wanted.

How can I revert the migration so that I can tweak it and try again?


回答1:


Assuming that you only want to go back one revision, use alembic downgrade with a relative migration identifier of -1:

alembic downgrade -1

This will run the downgrade() method of your latest revision and update the revision table to indicate the revision you're now at.

If you need to go back multiple migrations, run

alembic history

to view a list of all the migrations in your project (from newest to oldest), then copy and paste the identifier of the migration you want to go back to:

alembic downgrade 8ac14e223d1e

There's currently no command to delete migrations from your versions directory, so if you want to completely wipe away all trace of your bad migration, you'll need to delete the version file (like 4c009570237e_add_widget_table.py) manually.



来源:https://stackoverflow.com/questions/48242324/undo-last-alembic-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!