迁移不会回滚

问题描述:

我已经运行这个迁移:迁移不会回滚

class AddUniqueToLocationColumnName < ActiveRecord::Migration 
    def change 
    remove_index :locations, :name 
    add_index :locations, :name, unique: true 
    end 
end 

,现在我想回滚,但其示值误差:

StandardError: An error has occurred, this and all later migrations canceled: remove_index is only reversible if given a :column option.

我怎么可以回滚此迁移到我以前的版本?

+0

尝试将其更改为'remove_index:位置,柱:name' – max

+0

我想现在你必须从你的迁移中手动删除位置和名称索引使用remove_index方法。为此,您可以创建新迁移或更改为向上和向下状态。 –

+0

非常感谢。有效。只需要指定“列::名称”,而不是只有“名称”:) – Abhishek

尽量明确定义上下:

class AddUniqueToLocationColumnName < ActiveRecord::Migration 
    def self.up 
    remove_index :locations, column: :name 
    add_index :locations, :name, unique: true 
    end 

    def self.down 
    remove_index :locations, column: :name # remove unique index 
    add_index :locations, :name # adds just index, without unique 
    end 
end 
+1

它仍然不会work..max的解决方案工作。只需将“:name”更改为“column :: name”即可。 :),我根据你的代码编辑我的代码。所以都帮助;) – Abhishek

+0

不错!我用@max解决方案编辑了我的答案 –