Question

I made a mistake in setting my primary key on a table, say on field 'x'. An other field, say field 'y' I placed an unique constraint and to this field some other tables referenced as foreign key.

I noticed my mistake and dropped the primary key on field 'x' and placed it on 'y'. At this point I realized I could remove the unique constraint on 'y'. But now I get errors in doing so, telling me: cannot drop constraint 'y'_unique_constraint on table 'foo' because other objects depend on it.

I tried by doing a transaction and a 'set constraints all deffered' but that didn't help.

How can I remove this constraint without building my database from scratch? As far as I can see this unique constraint on 'y' is redundant now the primary key is on the same field.

Was it helpful?

Solution

I didn't realize at first that the foreign keys are referencing a index rather than a field. So by creating a new primary key on the same field didn't mean that the foreign keys switched to the new index.

I now dropped the unique constraint using cascade and re-added all the foreign keys, they are now using the primary key.

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