Celestial Bodies Database - Build a Celestial Bodies Database

Tell us what’s happening:
Hi guys, im this close to mentioning PSQL in my suicide note. i need help with creating foreign keys. I have attached screenshots below of the issue. Can someone please help me in creating foreign keys? the rule is Each “star” should have a foreign key that references one of the rows in galaxy

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Celestial Bodies Database - Build a Celestial Bodies Database

Link to the challenge:


now the thing is galaxy_id does exist as a column. i really dont know how to create a foreign key and no online forum has helped so far. pleaaaase help.

goodness! Don’t do it! :smiley:

I can’t see any screenshots but foreign keys are just a matter of creating a column first then linking it as a foreign key to another column in another table.
In this exercise make sure you use the correct names for the columns (galaxy_id in star should link to the galaxy_id column in the galaxy table)

there should be a galaxy_id column in both the star table and the galaxy table before you try to link them.

oh that i didnt know! youre my guardian angel!

1 Like

foreign key is created this way but test is still not passing :confused:

okay, check first what your two tables look like (use the \d star and \d galaxy)

Also what command did you use?
What error did you get?

also note that you will not see a checkmark until you add some rows so if you have created the constraint properly don’t worry if you don’t see the check mark yet while your tables are empty.

would you be able to help me with this error that im getting? I deleted my database and restarted my code 3 times but im always getting stuck. Really appreciate your help tho :slight_smile:

this error is trying to tell you that one of the values you are trying to insert is not valid as it is not present in the star_id column of the star table.

Edit: you probably need to specify the star_id when you are inserting into planet here.

1 Like