Thread: unique constraints
in 7.4 i'm getting an error message - UNIQUE constraint matching keys for table 'xxx' not found - any clues? -- regards kg http://www.ootygolfclub.org poor man's tally: http://avsap.sourceforge.net
On Wed, Jan 07, 2004 at 07:47:32PM +0530, Kenneth Gonsalves wrote: > in 7.4 i'm getting an error message - UNIQUE constraint matching keys for > table 'xxx' not found - any clues? It would be helpful to see the *exact* wording of the error message and the SQL statements that can be used to reproduce the error. I'd guess that you tried to create a foreign key constraint whose referenced column(s) didn't have a UNIQUE constraint: => CREATE TABLE foo (foo_id INTEGER NOT NULL); CREATE TABLE => CREATE TABLE bar (foo_id INTEGER NOT NULL REFERENCES foo (foo_id)); ERROR: there is no unique constraint matching given keys for referenced table "foo" The referenced column(s) should either be a PRIMARY KEY or have a UNIQUE constraint: => CREATE TABLE foo (foo_id INTEGER PRIMARY KEY); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo" CREATE TABLE => CREATE TABLE bar (foo_id INTEGER NOT NULL REFERENCES foo (foo_id)); CREATE TABLE See the "Foreign Keys" documentation for more info: http://www.postgresql.org/docs/current/static/ddl-constraints.html#DDL-CONSTRAINTS-FK -- Michael Fuhr http://www.fuhr.org/~mfuhr/
On Wednesday 07 January 2004 23:01, Michael Fuhr wrote: > On Wed, Jan 07, 2004 at 07:47:32PM +0530, Kenneth Gonsalves wrote: > > in 7.4 i'm getting an error message - UNIQUE constraint matching keys for > > table 'xxx' not found - any clues? > > It would be helpful to see the *exact* wording of the error message and > the SQL statements that can be used to reproduce the error. ok, got it now - the key in question was a 'serial' key. in older versions of postgres, since serial keys are anyway unique, apparently we could get away with not explicitly giving an unique constraint - sigh, a lot of work lies ahead ... -- regards kg http://www.ootygolfclub.org poor man's tally: http://avsap.sourceforge.net