On step 12 of the project Building an Inventory Database with PostgreSQL, it is stated:
Let’s ensure that for a part to be stored in
locations, it must already be registered in
parts. Write a constraint that forms the relationship between these two tables and ensures only valid
partsare entered into
I try the following:
ALTER TABLE locations ADD FOREIGN KEY (part_id) REFERENCES parts (id);
and I get an error:
ERROR: insert or update on table “locations” violates foreign key constraint “locations_part_id_fkey” DETAIL: Key (part_id)=(54) is not present in table “parts”.
parts.csv I see that the numbers for the
ids are up to 53. Any thought, please?
Link of the project below: