I had run this migration:
class AddUniqueToLocationColumnName < ActiveRecord::Migration
def change
remove_index :locations, :name
add_index :locations, :name, unique: true
end
end
And now I am trying to rollback but its showing error:
StandardError: An error has occurred, this and all later migrations canceled: remove_index is only reversible if given a :column option.
how can I roll back this migration to my previous version?
Try explicitly define up and 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With