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?

Colin 't Hart
9,48515 gold badges37 silver badges44 bronze badges
asked Aug 11, 2018 at 7:14
2
  • 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. Commented Aug 11, 2018 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, Commented Aug 13, 2018 at 5:26

1 Answer 1

1

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.

answered Aug 11, 2018 at 9:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.