Re: Foreign Key

Поиск
Список
Период
Сортировка
От Szymon Guz
Тема Re: Foreign Key
Дата
Msg-id z2qe4edc9361004221532s79e484a7t465f6a1bf6e66746@mail.gmail.com
обсуждение исходный текст
Ответ на Foreign Key  ("Bob Pawley" <rjpawley@shaw.ca>)
Список pgsql-general


2010/4/23 Bob Pawley <rjpawley@shaw.ca>
Hi
 
I don't understand what the following error means.
 
I am trying to add a foreign key to table image, that holds column device_id. This is to be controlled by column devices_id in table devices.
 
ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address) MATCH FULL;
 
ERROR:  insert or update on table "image" violates foreign key constraint "deviceidfk"
DETAIL:  Key (device_id)=(4022) is not present in table "devices".
 
Help appreciated.
 
Bob
Hi,
the error means that you try to insert some value to the column device_id in the image table that doesn't have a corresponding value in the devices table. If you want to insert something like this:

INSERT INTO image(device_id) VALUES ( 4022 );

there has to exist a record in the devices table that has the value 4022 in the corresponding column.

Oh, btw, the SQL command that you've shown doesn't add the foreign key on the image table.

regards
Szymon Guz

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: PSQL segmentation fault after setting host
Следующее
От: Tom Lane
Дата:
Сообщение: Re: I/O error during autovacuum