作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到一个问题,即使我有ON DELETE CASCADE
,当我的父行被删除时,我的子行也没有被删除。
我的父表如下所示:
CREATE TABLE `rw_profiles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
...
PRIMARY KEY (`id`),
KEY `profiles_logo_id_foreign` (`logo_id`),
KEY `profiles_subscription_id_foreign` (`subscription_id`),
KEY `profiles_deleted_at_name_index` (`deleted_at`,`name`),
CONSTRAINT `profiles_logo_id_foreign` FOREIGN KEY (`logo_id`) REFERENCES `rw_profile_logos` (`id`),
CONSTRAINT `profiles_subscription_id_foreign` FOREIGN KEY (`subscription_id`) REFERENCES `rw_subscription_types` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci
我的子表如下所示:
CREATE TABLE `rw_profile_access` (
`profile_id` int(10) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL,
...
UNIQUE KEY `profile_access_profile_id_user_id_unique` (`profile_id`,`user_id`),
KEY `profile_access_user_id_foreign` (`user_id`),
CONSTRAINT `profile_access_profile_id_foreign` FOREIGN KEY (`profile_id`) REFERENCES `rw_profiles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `profile_access_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `rw_users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci
外键“安装”在rw_profile_access
上没有问题,但是当我从rw_profiles
中删除一行时,相应的行(带有rw_profiles.id=
) 不会删除自身。profile_access
中的 rw_profile_access.profile_id
为什么删除父行时子行没有删除自身?
如果我运行下面的查询,则 foreign_key_checks
值为 on
。
SHOW Variables WHERE Variable_name='foreign_key_checks'
最佳答案
一定是 mariadb-server
(版本 10.0.10)出了问题,我将其删除,现在使用 mysql-server
代替,现在它的工作方式如下应该的。
关于mysql - 外部行没有被删除(有级联),为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23154984/
我是一名优秀的程序员,十分优秀!