0

I used pg_dump -U postgres -p 65432 --table=tableName --data-only --column-inserts DBName>fileName.sql to dump one particular table's rows. Now I need to insert them to another database but I get this error

insert or update on table "tableName" violates foreign key constraint "tableName_fk1"

How to proceed by dropping the foreign key contraint?

  • Do you have the data for the table referred to by the foreign key constraint? In that case you should load that data first. Otherwise you can drop a constraint using ALTER TABLE tableName DROP CONSTRAINT tableName_fk1;. No need to keep the constraint if you don't have the data it refers to. – Colin 't Hart Aug 11 '18 at 12:34
  • I do not have any data it refers to. I just want the rows to be inserted into the table. DROP CONSTRAINT worked like a charm, – Akila Rajkumar Aug 13 '18 at 5:26
0

the command is:

alter table "tableName" drop constraint "tableName_fk1"

The foreign key must already exist in the database where you want to import, since the dump was made --data-only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.