Celestial Bodies Database - Build a Celestial Bodies Database

I am having issues passing the test saying Each foreign key column should have the same name as the column it is referencing.

I created a new column in moon table called planet_id. then i tried linking it to the planet_id in the planet table but it keeps giving me an error saying:

ERROR: insert or update on table “moon” violates foreign key constraint “moon_planet_id_fkey”
DETAIL: Key (planet_id)=(13) is not present in table “planet”.

how do i resolve this?

Challenge: Celestial Bodies Database - Build a Celestial Bodies Database

Link to the challenge:

hi there,

It is possible that the data you have in the table is causing this issue.
Can you check what data you have? (select * from moon)

moon has 20 rows while planet has 12 rows

okay so it is possible that your planet column is causing this problem if it contains any data that doesn’t exist already in the planet’s planet_id column.

Also note that you must have the exact name of the planet_id in both tables (not planet, planet_id for both)

this is the tables presently. i matched the planet column on moon to the name column on planet. they linked without error
cant’ still figure out why its giving the same error when i try to add the foreign key

hi again,

it is because the values inside the planet_id inside the moon table are incorrect.
You only have 12 rows in planet, therefore, the planet_id 13-20 are invalid inside of moon’s table.