How can I add unique: true
constraint to already existing index in Rails database?
I tried to migrate by
def change
add_index :editabi
Faster way using add_index_options:
def change
add_index_options :editabilities, [:user_id, :list_id], unique: true
end
Remove the old index and add it again with the new constraint:
def change
remove_index :editabilities, [:user_id, :list_id]
add_index :editabilities, [:user_id, :list_id], unique: true
end