I have the following create-table-query:
`CREATE TABLE `order_meta` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) DEFAULT NULL,
`meta_key` varchar(255) DEFAULT NULL,
`meta_value` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `order_meta_key_index` (`order_id`,`meta_key`),
CONSTRAINT `order_meta_order_id` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=34064 DEFAULT CHARSET=utf8;`
when i run an export / mysqldump, it gives me. running SHOW CREATE TABLE order_meta
gives me the same, so i guess thats where the problem lies.
`CREATE TABLE `order_meta` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) DEFAULT NULL,
`meta_key` varchar(255) DEFAULT NULL,
`meta_value` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `order_meta_key_index` (`order_id`,`meta_key`),
CONSTRAINT `order_meta_order_id` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=34064 DEFAULT CHARSET=utf8;`
notice the 'ON UPDATE RESTRICT' that has been removed. After when i delete a row from 'orders' the rows in 'order_meta' are not removed. When i remove the foreign key and re-add with the on update, it works again. Is this expected behavior or am i missing something here?
`alter table order_meta drop FOREIGN KEY `order_meta_order_id`;`
`alter table order_meta add CONSTRAINT `order_meta_order_id` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT;`
我想这与创建 mysqldump 的过时工作台有关。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.