Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

migration not rolling back

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?

like image 966
abhishek Avatar asked Oct 19 '22 09:10

abhishek


1 Answers

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
like image 168
Adriano Godoy Avatar answered Nov 15 '22 06:11

Adriano Godoy