0

How to set FOREIGN KEY (packet_id) REFERENCES girvi_packet(id) DEFERRABLE INITIALLY DEFERRED to NULL ?

If parent get deleted postgreSQL raises error that parent is missing I want to suppress this behavior. This constraint is added by default by some 3rd part tool. But my use case demands otherwise.

Vaibhav Jain
  • 5,287
  • 10
  • 54
  • 114

1 Answers1

0

The purpose of the foreign key is to prevent orphan children. The only way you can do is to delete the constrain

ALTER TABLE ... DROP CONSTRAINT ...
Tantowi Mustofa
  • 677
  • 4
  • 8
  • `egirvidb=# alter table girvi_transactionauditlogentry drop constraint girvi_transactionauditlog_packet_id_4b31e38d_fk_girvi_packet_id, add constraint girvi_t ransactionauditlog_packet_id_4b31e38d_fk_girvi_packet_id foreign key (packet_id) references girvi_packet(id) on delete set null;` Yes I altered the table now its working – Vaibhav Jain Mar 02 '16 at 19:06
  • Is there a way to dynamically get the all constraints and then run alter on them ?? – Vaibhav Jain Mar 02 '16 at 19:08
  • http://stackoverflow.com/questions/1152260/postgres-sql-to-list-table-foreign-keys – Tantowi Mustofa Mar 04 '16 at 01:12