如何删除 Rails 3 中的迁移文件 [英] How to delete migration files in Rails 3

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

问题描述

我想移除/删除迁移文件.我该怎么做呢?我知道这里有类似的问题,但作为更新,有没有比执行脚本/销毁更好的方法?

I would like to remove/delete a migration file. How would I go about doing that? I know there are similar questions on here but as an update, is there a better way than doing script/destroy?

此外,如果我移除/删除迁移,我应该执行 db:reset 还是 db:drop?

Also, should I do a db:reset or db:drop if I remove/delete a migration?

推荐答案

我通常:

  1. 在所有环境上执行 rake db:migrate VERSION=XXX 到我要删除的版本之前的版本.
  2. 手动删除迁移文件.
  3. 如果有待处理的迁移(即,我删除的迁移不是最后一个),我只需再次执行新的 rake db:migrate.
  1. Perform a rake db:migrate VERSION=XXX on all environments, to the version before the one I want to delete.
  2. Delete the migration file manually.
  3. If there are pending migrations (i.e., the migration I removed was not the last one), I just perform a new rake db:migrate again.

如果您的应用程序已经在生产或暂存阶段,编写另一个会破坏您的表或列的迁移会更安全.

If your application is already on production or staging, it's safer to just write another migration that destroys your table or columns.

另一个很好的迁移参考是:http://guides.rubyonrails.org/migrations.html

Another great reference for migrations is: http://guides.rubyonrails.org/migrations.html

这篇关于如何删除 Rails 3 中的迁移文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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