I have a following table:
CREATE TABLE IF NOT EXISTS `Tree` (
`id` int(10) NOT NULL,
`parent` int(10) DEFAULT NULL,
`text` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `parent` (`parent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Tree` (`id`, `parent`, `text`) VALUES
(1, 1, '1'),
(2, 1, '1.1'),
(3, 1, '1.2'),
(4, 1, '1.3');
ALTER TABLE `Tree` ADD CONSTRAINT `tree_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `tree` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
After having executed all of the above statements a problem observed for the following one:
UPDATE `Tree` SET `id` = '10' WHERE `Tree`.`id` = 1
While it is expected that changing the main id would cause all linked parent
records to update automatically due to ON UPDATE CASCADE
constraint. Aren't these cascading referential integrity constraints are all about?
test
.tree
, CONSTRAINTtree_ibfk_1
FOREIGN KEY (parent
) REFERENCEStree
(id
) ON DELETE CASCADE ON UPDATE CASCADE)