HI I'm new to postgresql environment so been lost for a while. I want to keep my data when parent entity is deleted. I want to know how to make 'ON DELETE SET NULL' for postgresql database. Please give me a clue.
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.