Celestial Bodies DB: dump_pg and UNIQUE constraint problems

Hi im doing the Celestial Body DB have two problems, first the tutorial says i can lose all my progress if i live de VM. so im trying to save what i did so far in the universe.sql with this command line, in the bash terminal, before logging into de database.

pg_dump -cC --inserts -U freecodecamp universe > universe.sql

The above command gives me an error: pg_dump: error: too many command-line arguments (“first is universe”)

The next problem I am facing is related to the database itself, I made a mistake by setting a UNIQUE CONSTRAINT to a column that has a boolean value, so when I repeat the value (true) entering data I get an error.

I want to see what i’m doing wrong as I can’t remove it, I’m trying with the following

ALTER TABLE galaxy DROP CONSTRAINT galaxy_local_group UNIQUE (local_group);

But isn’t working, Should i delete the entire column and make it again? maybe it’s easier but i want to know what im doing wrong.

Thanks, and sorry about my english.

For the costraint issue is more of a syntax problem you should use the following query:
ALTER TABLE galaxy
DROP CONSTRAINT local_group
It should suffice.

On the “pg_dump -cC --inserts -U freecodecamp universe”, for what i can see you are:
-c: dropping the table;
-C: creating a table;
–inserts: dumping as inserts command every data (but i suggest you to use a more safe --column-inserts)

In this case I think that you are trying to export on the sql file something that doesn’t exist, read the documentation here PostgreSQL: Documentation: 15: pg_dump and find what would be the commands that fits the best for you task.

1 Like