0

MySQL table structure:

CREATE TABLE `admin_folders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `ix_admin_folders_parent_id` (`parent_id`),
KEY `ix_admin_folders_name` (`name`),
KEY `ix_admin_folders_user_id` (`user_id`),
CONSTRAINT `admin_folders_parent_id_id` FOREIGN KEY (`parent_id`) REFERENCES `admin_folders` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8

When I have the following entries in this table:

enter image description here

Due to the ON DELETE CASCADE constraint I expected that the rows with id 14 and 15 are getting deleted when I delete the one with id 13 since they're referenced.

But it's not deleting the referenced rows.

Where is my fault in that thought process?

Server version: 5.6.33-0ubuntu0.14.04.1-log - (Ubuntu)

UPDATE It is working, it seems to be a bug in PhpMyAdmin to not properly reload the result set.

Andreas Hinderberger
  • 1,505
  • 23
  • 41
  • 1
    It works fine for me: http://rextester.com/TEFQPF62061 BTW, you have a syntax error in your `CREATE TABLE`, an extra comma at the end of the `CONSTRAINT` line. – Barmar Sep 07 '18 at 20:36
  • Is it possible that it's considered as a recursive CTE which is supported up from MySQL and not in 5? – Andreas Hinderberger Sep 07 '18 at 20:41
  • Sorry for the extra comma. I removed some note related constraints – Andreas Hinderberger Sep 07 '18 at 20:41
  • 1
    rextester is using MySQL 5.7. Also see this question from 3 years ago that says it should work: https://stackoverflow.com/questions/30973033/how-to-delete-cascade-when-parentid-and-childid-are-on-the-same-table – Barmar Sep 07 '18 at 20:46
  • Thanks @Barmar . It seems it is a bug in PhpMyAdmin not refreshing properly. I'm sorry for the confusion. It is working. – Andreas Hinderberger Sep 07 '18 at 21:04

0 Answers0