1、在使用贵公司的社区版OceanBase ,版本号:5.7.25-OceanBase_CE-v4.1.0.0时候,发现在多表关联有外键关系时候,执行删除操作报错:Cannot delete or update a parent row: a foreign key constraint fails
2、表关系描述如下:
1) 父表t_a_group,群组表
CREATE TABLE `t_a_group` (
`oid` bigint(20) NOT NULL AUTO_INCREMENT,
`group_name` varchar(100) COLLATE utf8mb4_bin NOT NULL,
`user_oid` bigint(20) NOT NULL,
PRIMARY KEY (`oid`),
CONSTRAINT `FK_ISS_GRP_ISS_OID` FOREIGN KEY (`user_oid`) REFERENCES `test_db`.`t_user`(`oid`) ON UPDATE RESTRICT ON DELETE RESTRICT ,
KEY `FK_ISS_GRP_ISS_OID` (`user_oid`) BLOCK_SIZE 16384 LOCAL
) AUTO_INCREMENT = 1000008 AUTO_INCREMENT_MODE = 'ORDER' DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0;
2)子表t_a_group_privilege,权限表
CREATE TABLE `t_a_group_privilege` (
`oid` bigint(20) NOT NULL AUTO_INCREMENT,
`access_id` varchar(40) COLLATE utf8mb4_bin DEFAULT NULL,
`a_group_oid` bigint(20) NOT NULL,
PRIMARY KEY (`oid`),
CONSTRAINT `FK_ISS_GRP_PRVG_ISS_GRP_OID` FOREIGN KEY (`a_group_oid`) REFERENCES `test_db`.`t_a_group`(`oid`) ON UPDATE RESTRICT ON DELETE RESTRICT ,
KEY `FK_ISS_GRP_PRVG_ISS_GRP_OID` (`a_group_oid`) BLOCK_SIZE 16384 LOCAL
) AUTO_INCREMENT = 1000033 AUTO_INCREMENT_MODE = 'ORDER' DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0;
说明:上述父表与子表通过外键关联
3、执行删除操作
1)通过代码执行,执行下面两行代码,报错 :Cannot delete or update a parent row: a foreign key constraint fails
aGroupPrivilegeService.delete(oid);
aGroupService.delete(oid);
2)通过SQL语句执行,一样报错:Cannot delete or update a parent row: a foreign key constraint fails
BEGIN;
delete from t_a_group_privilege where oid = 1000031;
delete from t_a_group where oid=1000006;
COMMIT;
---------------------------------------- 分割线 ------------------------------------------------------------
提问:
1、请问是什么原因导致删除不掉?
2、有什么解决方案吗?