撤消上次 Alembic 迁移 [英] Undo last Alembic migration

查看:36
本文介绍了撤消上次 Alembic 迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 alembic revision --autogenerate 创建了一个迁移,用 alembic upgrade head 将它应用到我的开发数据库,​​然后意识到这不是我想要的.

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?

推荐答案

假设您只想返回一个修订版,使用 alembic downgrade 带有 相对迁移标识符 -1:

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

alembic downgrade -1

这将运行最新版本的 downgrade() 方法并更新版本表以指示您现在所在的版本.

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

目前没有命令可以从您的版本目录中删除迁移,因此如果您想完全清除所有错误迁移的痕迹,您需要删除版本文件(例如 4c009570237e_add_widget_table.py) 手动.

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.

这篇关于撤消上次 Alembic 迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆