Celestial Bodies Database - Build a Celestial Bodies Database

Tell us what’s happening:
Describe your issue in detail here.
I Have an Urgent Query that needs to be adressed that why is this error coming & Why is this method used Celestial Bodies Database | FreeCodeCamp - YouTube Pls help Pls help

Your code so far

universe=> INSERT INTO star(star_id, radius, color, name, galaxy_id) VALUES(1092, 123461234, 'yellow', 'joe', 1);
ERROR:  duplicate key value violates unique constraint "star_pkey"
DETAIL:  Key (star_id)=(1092) already exists.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0

Challenge: {{challengeTitle}} Celestial Bodies Database - Build a Celestial Bodies Database

Link to the challenge:

Did you set star_id as SERIAL? If so, I don’t think you should be entering values for that attribute at all. Otherwise, check your star() table since you might already have an entry with the same star_id. Since star_id is a primary key, you cannot have multiple entries with the same value.

In the Video Which is Highlighted at 34:52 then How can I finish the project

It was first two ticks now one Tick!!

@MrRox1337 Any update’s?

Remove the ’ after VALUES as that is incorrect syntax.

You are also inserting star_id and galaxy_id as string type when they’re integer types.

Also as far as I know, from the original error that you’ve posted, if it says that the “id” exists then you need to use UPDATE instead of INSERT.

Try the line
INSERT INTO star(radius, color, name, galaxy_id) VALUES (12432, 'yellow', 'gary',1);
Since star_id is a PRIMARY KEY of type SERIAL, you don’t need to mention it at all (unless you want to give it a specific value which is not yet used in the table).

If you want to use an already preset star_id, you will have to use
UPDATE star SET radius = 12432, color='yellow', name='gary', galaxy_id=1 WHERE id=<your desired star_id here>;
Replace <your desired star_id here> with the specific entry you wish to update.

Don’t forget to run the basic SELECT * FROM star; to see all the entries before you make any changes.


You’ve written the statement incorrectly. Please review your UPDATE statement. There is no “)” in my solution to your problem.

I should also add that you’re using an UPDATE statement when you only have 1 entry in the star table with star_id=1092. If you are planning to create a new entry please review the INSERT statement I mentioned in the solution. But if you wish to make changes to your current entry at star_id=1092, then use the UPDATE statement.