[openstack-dev] [Keystone]ON DELETE RESTRICT VS ON DELETE CASCADE

Chen, Wei D wei.d.chen at intel.com
Sun Mar 8 03:37:07 UTC 2015


Hi,

I did some homework to follow up the inline comment about on delete cascade subclauses of the foreign key clause[1], when ' ON
DELETE CASCADE ' is given, delete a recode from parent table will DELETE all the corresponding rows from the CHILD table
automatically *without any warning*. 'ON DELETE RESTRICT' looks different, it will fail complaining about the existing child rows,
this is the default foreign key relationship behavior, this seems give end user a chance to double check the data.

I did a quick test against the table 'endpoint_group', the output error message like below,
mysql> delete from endpoint_group;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`keystone`.`project_endpoint_group`,
CONSTRAINT `project_endpoint_group_ibfk_1` FOREIGN KEY (`endpoint_group_id`) REFERENCES `endpoint_group` (`id`))

I am a little confused about two different subclauses as both of them can be found in the table definition of SQL backends, it hard
to say which one is better, is it worthwhile to move all of them to "ON DELETE CASCADE" or "ON DELETE RESTRICT"?


[1] https://review.openstack.org/#/c/151931/5/keystone/contrib/endpoint_filter/migrate_repo/versions/002_add_endpoint_groups.py

Best Regards,
Dave Chen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6648 bytes
Desc: not available
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20150308/13bba95d/attachment.bin>


More information about the OpenStack-dev mailing list