gpt4 book ai didi

ruby-on-rails - 迁移不回滚

转载 作者:行者123 更新时间:2023-12-01 23:08:20 24 4
gpt4 key购买 nike

我已经运行了这个迁移:

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 migrationscanceled: remove_index is only reversible if given a :column option.


如何将此迁移回滚到我以前的版本?

最佳答案

尝试明确定义 up 和 down:

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

关于ruby-on-rails - 迁移不回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37276104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com