Referencing "less-unique" foreign keys

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: pgsql-general(at)postgresql(dot)org
Cc: vincent(at)magproductions(dot)nl
Subject: Referencing "less-unique" foreign keys
Date: 2005-08-09 12:31:16
Message-ID: 42F8A214.5050903@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

We migrated a database from version 7.3 something to 7.4.7 a while ago,
and ever since that time we can't make new foreign keys to a particular
table. The problem is that the primary key on that table is on two
columns that are unique together, but that only one of them should be
referenced from the other table.

Tables are as follows:

CREATE TABLE localization (
localization_id text NOT NULL,
language_id integer NOT NULL REFERENCES language(language_id) MATCH FULL,
content text NOT NULL
PRIMARY KEY (localization_id, language_id)
);

CREATE TABLE description (
description_id serial PRIMARY KEY,
content text NOT NULL REFERENCES localization(localization_id)
);

I'm not sure how we got the "content" column from "description" to
reference "localization" back in version 7.3. Fact is, we can't seem to
do this anymore since version 7.4:

psql> ALTER TABLE description ADD CONSTRAINT fk_description_content
FOREIGN KEY (content) REFERENCES localization(localization_id);
ERROR: there is no unique constraint matching given keys for referenced
table "localization"

Any way around this?

--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

//Showing your Vision to the World//

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-08-09 13:05:17 Re: Referencing "less-unique" foreign keys
Previous Message Piotr Sulecki 2005-08-09 12:12:49 index being ignored for "limit n" queries