gpt4 book ai didi

mysql - 外部行没有被删除(有级联),为什么?

转载 作者:行者123 更新时间:2023-11-30 00:22:04 25 4
gpt4 key购买 nike

我遇到一个问题,即使我有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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com