I created a unique index on my model like so:
add_index(:courses, :name, unique: true)
I no longer require the name to be unique. I think I have the same problem as this person, so I worked through those suggestions to no avail.
I receive errors like "ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_courses_on_name" when I try to add a record with the same name.
To remove the unique constraint I've tried:
remove_index :courses, :name
(migration succeeds, but later I get the same error suggesting there is still a uniqueness constraint)
execute "ALTER TABLE courses DROP CONSTRAINT unique_index_courses_on_name"
execute "ALTER TABLE courses DROP CONSTRAINT index_courses_on_name"
execute "ALTER TABLE courses DROP CONSTRAINT unique_name"
execute "ALTER TABLE courses DROP CONSTRAINT name"
execute "ALTER TABLE courses DROP INDEX index_courses_on_name"
execute "ALTER TABLE courses DROP INDEX courses_on_name"
execute "DROP INDEX unique_courses_name"
(PG::UndefinedObject: ERROR: index "unique_courses_name" does not exist)
execute "ALTER TABLE courses disable CONSTRAINT unique_courses_name"
(PG::SyntaxError: ERROR: syntax error at or near "CONSTRAINT" LINE 1: ALTER TABLE courses disable CONSTRAINT unique_courses_name)
execute "ALTER TABLE courses DROP INDEX unique_courses_name"
I'm on psql 9.4.4, Rails 4.2, and my last ounce of sanity. Thanks everyone.
psql
, e.g.\dt courses
– Craig Ringer