I am trying to delete child nodes using the parent_id, id. like the following...
id | parent_id
1 | 0
2 | 1
3 | 2
deleting id 2 should also delete id 3. How to get the follow code to work?
i am using mysql 5.1. this code gives a query syntax error on line number... but no error message.
"CREATE TABLE test(
`id` INT(20) NOT NULL AUTO_INCREMENT,
`parent_id` INT( NOT NULL,
`title` TEXT NOT NULL,
FOREIGN KEY (parent_id) REFERENCES test (id) ON DELETE CASCADE,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 ";
when i use the following code, there is no errors.
"CREATE TABLE test(
`id` INT(20) NOT NULL AUTO_INCREMENT,
`parent_id` INT( NOT NULL,
`title` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=myisam DEFAULT CHARSET=utf8 ";
notice in the above code that i have changed the word INNODB to MYISAM for the ENGINE and removed the FOREIGN KEY. this code works but no "on delete cascade".