Reputation: 13
I added a column to a table through a migration.It's generate a migration file i add the following thing. Then migrated.After adding that i realise to add forgot unique: true that migration. How to add unique: true
to this migration file. Syntax please.
In migration
def change
add_column :tasks, :position, :integer
end
Upvotes: 0
Views: 1488
Reputation: 6096
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
(Credit: I directly lifted this answer from Baldrick's answer here. Upvote him before you upvote me ;) )
Upvotes: 1