Errors setting foreign keys in Postgresql
Posted: Fri Dec 14, 2018 3:20 pm
Hello, I am receiving several errors when setting foreign keys in Postgresql. Wondering if anyone has suggestions? The errors fall into two categories - here are examples of each with the SQL syntax that fails:
Error type 1 (2 cases)
ALTER TABLE tls226_person_orig ADD FOREIGN KEY (person_id) REFERENCES tls906_person(person_id);
ERROR: insert or update on table "tls226_person_orig" violates foreign key constraint "tls226_person_orig_person_id_fkey"
DETAIL: Key (person_id)=(52249751) is not present in table "tls906_person".
(Note: In both cases, it looks like the referenced table is missing a key.)
Error type 2 (5 cases)
ALTER TABLE tls228_docdb_fam_citn ADD FOREIGN KEY (docdb_family_id) REFERENCES tls201_appln(docdb_family_id);
ERROR: there is no unique constraint matching given keys for referenced table "tls201_appln"
I am not a database expert, so any help would be very appreciated!
Error type 1 (2 cases)
ALTER TABLE tls226_person_orig ADD FOREIGN KEY (person_id) REFERENCES tls906_person(person_id);
ERROR: insert or update on table "tls226_person_orig" violates foreign key constraint "tls226_person_orig_person_id_fkey"
DETAIL: Key (person_id)=(52249751) is not present in table "tls906_person".
(Note: In both cases, it looks like the referenced table is missing a key.)
Error type 2 (5 cases)
ALTER TABLE tls228_docdb_fam_citn ADD FOREIGN KEY (docdb_family_id) REFERENCES tls201_appln(docdb_family_id);
ERROR: there is no unique constraint matching given keys for referenced table "tls201_appln"
I am not a database expert, so any help would be very appreciated!