ruby-on-rails - 如何还原已 checkin 到 git 的 Rails 迁移

标签 ruby-on-rails git rails-migrations

在我的 development/feature 分支上,我提交了 20150818113106_add_team_id_to_account.rb(它向 Account 添加了一列)& schema.rb 应用迁移的结果。此提交已被推送,并且还存在于 origin/development/feature 上。

现在我想还原此更改 - 毕竟我不想将此列添加到 Account。我不知道是否应该因此恢复 git 提交,或者运行 db:migrate:down 并提交其结果,或者两者都提交,或者两者都不提交。

最佳答案

解决方案(一)

您可以运行以下命令来回滚迁移:

rake db:migrate:down VERSION=2015081811310

然后从存储库中删除迁移,如下所示:

git rm 20150818113106_add_team_id_to_account.rb

然后推送这些更改,如果您部署在服务器上,请再次执行这些步骤。

解决方案(二)

创建另一个迁移以删除此列,如下所示:

rails g migration remove_team_id_from_accounts team_id:integer 

然后rake db:migrate,然后提交并推送

关于ruby-on-rails - 如何还原已 checkin 到 git 的 Rails 迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32310794/

相关文章:

eclipse - 混帐 + eclipse : 401 Unauthorized Error

git - 相当于 git-archive 直接到磁盘,没有任何 tar 处理

ruby-on-rails - Rails 迁移添加一个 null : false column with an initial value that's not an ongoing default

ruby-on-rails - Bundler 不允许我安装 gems

javascript - 使用 Rails 以 Haml 形式执行 JavaScript

javascript - 如何添加/删除参数以与 jquery 链接

mysql - Rails 迁移似乎已完成,但 rake 仍将迁移显示为挂起

jquery - Rails 3.1 AJAX 表单 - "ActionView::Template::Error (undefined method ` gsub' for #<ActionDispatch::Flash::FlashHash:0x00000102b73b78>):"

css - Gulp + Sass + Git 工作流程

mysql - 在没有 key 长度的 key 规范中使用的 Rails BLOB/TEXT 列