[MDEV-26034] Update cascade failed Created: 2021-06-28  Updated: 2021-07-17  Resolved: 2021-07-17

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Update
Affects Version/s: 10.3.29, 10.5.10
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: grgeehr Assignee: Sergei Golubchik
Resolution: Not a Bug Votes: 0
Labels: innodb
Environment:

Ubuntu20.04: 10.3.29
Docker:10.5.10



 Description   

create table Dep(
    id INT UNSIGNED AUTO_INCREMENT primary key,
    dep varchar(255) not null unique,
    dep_sjm varchar(255),
    p_dep INT UNSIGNED default NULL
);
ALTER TABLE Dep
    ADD FOREIGN KEY (p_dep)
    REFERENCES Dep (id)
    ON UPDATE CASCADE;
 
insert into Dep(id,dep,dep_sjm) values (209604,"sales department","XSB");
 
insert into Dep(id, dep, dep_sjm, p_dep) values (203634,"sales department 1","XSB",209604);
update Dep set id=48615 where id=209604;

output: ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`test`.`Dep`, CONSTRAINT `Dep_ibfk_1` FOREIGN KEY (`p_dep`) REFERENCES `Dep` (`id`) ON UPDATE CASCADE)



 Comments   
Comment by Sergei Golubchik [ 2021-07-17 ]

https://mariadb.com/kb/en/foreign-keys/#limitations

If ON UPDATE CASCADE recurses to update the same table it has previously updated during the cascade, it acts like RESTRICT.

Generated at Thu Feb 08 09:42:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.