Referencing "less-unique" foreign keys

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Referencing "less-unique" foreign keys
Дата
Msg-id 42F8A214.5050903@magproductions.nl
обсуждение исходный текст
Ответы Re: Referencing "less-unique" foreign keys  (Martijn van Oosterhout <kleptog@svana.org>)
Re: Referencing "less-unique" foreign keys  (Richard Huxton <dev@archonet.com>)
Список 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@magproductions.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//

В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Case sensitivity
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Referencing "less-unique" foreign keys