I have a table that contains a tree in oracle.
MY_TABLE
node_id
parent_id
How do I add a cascade delete when the root of the tree is not going to have a parent?
Right now the parent id is set to -1 for the root. When I try this I get the following error:
Error starting at line 1 in command:
ALTER TABLE regional_defaults_working
add CONSTRAINT regional_defaults_wk_delete
FOREIGN KEY (parent_id)
REFERENCES regional_defaults_working(node_id)
ON DELETE CASCADE
Error report:
SQL Error: ORA-02298: cannot validate (XVTEST.REGIONAL_DEFAULTS_WK_DELETE) - parent keys not found
02298. 00000 - "cannot validate (%s.%s) - parent keys not found"
*Cause: an alter table validating constraint failed because the table has
child records.