Building Inventory Database with PostgreSQlL

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 in parts . Write a constraint that forms the relationship between these two tables and ensures only valid parts are entered into locations .

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 ids are up to 53. Any thought, please?

Link of the project below:
(link)

Hello,

There’s a very good chance that you still need to complete the 2nd part of Step 5.

Step 5 is the where you test to make sure that the constraint you added in Step 4 was successful by attempting to INSERT a part with an id of 54 without a description so that it fails. However, the last sentence of Step 5 mentions examining the error message and updating the INSERT so that it works (by including a description since it’s required now). Once you successfully add part id 54 to the database, Step 12 will work too.