ON DELETE SET NULL in postgres

ON DELETE SET NULL is a standard foreign key constraint option.

CREATE TABLE some_child (
    parent_id integer references parent(id) on delete set null
);

or:

ALTER TABLE some_child 
ADD CONSTRAINT parent_id_fk 
FOREIGN KEY (parent_id) REFERENCES parent(id) 
ON DELETE SET NULL;

See the documentation.

In future posts make sure you include your PostgreSQL version and explain what you’ve already tried.

Leave a Comment