PostgreSQL 8.3.8 on Gentoo Linux. I've got a junction table:
CREATE TABLE participants ( person_fk INTEGER REFERENCES persons (person_id), event_fk INTEGER REFERENCES events (event_id) ON DELETE CASCADE, sort_order INTEGER NOT NULL DEFAULT 1, is_principal BOOLEAN NOT NULL DEFAULT TRUE, PRIMARY KEY (person_fk, event_fk) ); CREATE INDEX event_key ON participants (event_fk); CREATE INDEX person_key ON participants (person_fk); Now I want to add some text to a few participants, but as this will probably only be for a few per cent, I try to create an extra table like this: pgslekt=> CREATE TABLE participant_notes ( pgslekt(> person_fk INTEGER NOT NULL REFERENCES participants (person_fk), pgslekt(> event_fk INTEGER NOT NULL REFERENCES participants (event_fk) ON DELETE CASCADE, pgslekt(> part_note TEXT, pgslekt(> PRIMARY KEY (person_fk, event_fk) pgslekt(> ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "participant_notes_pkey" for table "participant_notes" ERROR: there is no unique constraint matching given keys for referenced table "participants" I fail to see what is the problem. I even tried to add a unique constraint to participants: pgslekt=> alter table participants add constraint unique_person_event unique (person_fk, event_fk); NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index "unique_person_event" for table "participants" ALTER TABLE But I still get the same error message as above. This works fine, naturally: pgslekt=> CREATE TABLE participant_notes ( pgslekt(> person_fk INTEGER NOT NULL references persons (person_id), pgslekt(> event_fk INTEGER NOT NULL references events (event_id) ON DELETE CASCADE, pgslekt(> part_note TEXT, pgslekt(> PRIMARY KEY (person_fk, event_fk) pgslekt(> ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "participant_notes_pkey" for table "participant_notes" CREATE TABLE However, I think that this table should reference participants, not the primary tables persons and events. -- Leif Biberg Kristensen http://solumslekt.org -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql