如何回滚特定的迁移? [英] How to rollback a specific migration?

查看:156
本文介绍了如何回滚特定的迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下迁移文件 db\migrate\20100905201547_create_blocks.rb

如何具体回滚该迁移文件?

How can I specifically rollback that migration file?

推荐答案

rake db:rollback STEP=1

如果要回滚的迁移是最后一次应用,则是一种方法。您可以用1代替要返回的许多迁移。

Is a way to do this, if the migration you want to rollback is the last one applied. You can substitute 1 for however many migrations you want to go back.

例如:

rake db:rollback STEP=5

还将回滚发生的所有迁移稍后(4、3、2和1)。

Will also rollback all the migration that happened later (4, 3, 2 and also 1).

要将所有迁移回滚到(包括)目标迁移,请使用:(已添加此更正的命令在所有评论指出原始帖子中的错误之后)

To roll back all migrations back to (and including) a target migration, use: (This corrected command was added AFTER all the comments pointing out the error in the original post)

rake db:migrate VERSION=20100905201547

为了回滚仅一个特定的迁移(无序),请使用:

In order to rollback ONLY ONE specific migration (OUT OF ORDER) use:

rake db:migrate:down VERSION=20100905201547

请注意,这不会回滚任何中间的迁移-仅列出其中的一个。如果这不是您想要的,则可以安全地运行 rake db:migrate ,它将仅重新运行该命令,而跳过以前未回滚的其他命令。

Note that this will NOT rollback any interceding migrations -- only the one listed. If that is not what you intended, you can safely run rake db:migrate and it will re-run only that one, skipping any others that were not previously rolled back.

如果您想按顺序迁移单个迁移,则还有一个相反的 db:migrate:up

And if you ever want to migrate a single migration out of order, there is also its inverse db:migrate:up:

rake db:migrate:up VERSION=20100905201547

这篇关于如何回滚特定的迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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