开发者

MySQL ON UPDATE CASCADE with self-referencing

开发者 https://www.devze.com 2023-03-07 14:36 出处:网络
According to http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html If ON UPDATE CASCADE or ON UPDATE SET

According to http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html

If ON UPDATE CASCADE or ON UPDATE SET NULL recurses to update the开发者_Python百科 same table it has previously updated during the cascade, it acts like RESTRICT

My reading of this means that at least one cascading update should be allowed, and thereafter any further updates should be RESTRICTed. This is not the case with a self-referencing table. No updates are done, only this error is given:

ERROR 1451 (23000) at line 1: Cannot delete or update a parent row: a foreign key constraint fails ('temp'.'tableA', CONSTRAINT 'FK5E61277C3139BCA6' FOREIGN KEY ('foreign_key_id') REFERENCES 'tableA' ('id') ON UPDATE CASCADE)

Do you agree with this? Why is this the case?

0

精彩评论

暂无评论...
验证码 换一张
取 消