Hi,
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 inparts
. Write a constraint that forms the relationship between these two tables and ensures only validparts
are entered intolocations
.
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”.
Checking the parts.csv
I see that the numbers for the id
s are up to 53. Any thought, please?
Link of the project below:
(link)