Postgres Dump File – How to Disable Foreign Key Constraints

foreign keypg-dumppsql

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?

Best Answer

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.