[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
I did some homework to follow up the inline comment about on delete cascade subclauses of the foreign key clause, 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"?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 6648 bytes
Desc: not available
More information about the OpenStack-dev