I created a table with FOREIGN KEY and cannot insert anything.
CREATE TABLE menus ( id int(10), parent_id int(10), label varchar(255), PRIMARY KEY (id), FOREIGN KEY (parent_id) REFERENCES menus (id) );
I need a FOREIGN KEY to automatically remove children when a parent has been deleted. This table was created successfully, but I cannot insert anything.
INSERT INTO `menus` (`parent_id`, `label`) VALUES ('1', 'label1');
or
INSERT INTO `menus` (`label`) VALUES ( 'label1');
I really do not want to look for children in php code, so I need to somehow create a simple table with three columns and automatically drop all children and children.
source share