Question

Trying to execute this statement in a rails migration to generate a multi column unique constraint/index:

add_index :contributors, [:project_id, :user_id], :unique=>true

I've also tried providing an optional :name to the method, but still getting the failure. There are no existing keys in this table

Mysql::Error: Duplicate entry '5-9' for key 'distinct_user_and_project': CREATE UNIQUE INDEX `distinct_user_and_project` ON `contributors` (`project_id`, `user_id`)

How do I create this short of using execute and straight sql? Thanks.

Was it helpful?

Solution

Its clearly in error (Duplicate entry '5-9') that your data is not unique so You can't add such index there

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top