<div dir="ltr">In general I'd say that cascade is the right approach. There are some very limited cases where restrict should be used. Overall, I'd like to see less reliance on FK constraints anywhere. The reason for using Cascade is that we should be very specific in our code to prevent deletion independent of the backend (move these checks to the controller level) if we want to prevent deletion cascades. In short, we should not rely on an implementation specific detail to know if we can / cannot delete something.<div><br></div><div>--Morgan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 7, 2015 at 7:37 PM, Chen, Wei D <span dir="ltr"><<a href="mailto:wei.d.chen@intel.com" target="_blank">wei.d.chen@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I did some homework to follow up the inline comment about on delete cascade subclauses of the foreign key clause[1], when ' ON<br>
DELETE CASCADE ' is given, delete a recode from parent table will DELETE all the corresponding rows from the CHILD table<br>
automatically *without any warning*. 'ON DELETE RESTRICT' looks different, it will fail complaining about the existing child rows,<br>
this is the default foreign key relationship behavior, this seems give end user a chance to double check the data.<br>
<br>
I did a quick test against the table 'endpoint_group', the output error message like below,<br>
mysql> delete from endpoint_group;<br>
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`keystone`.`project_endpoint_group`,<br>
CONSTRAINT `project_endpoint_group_ibfk_1` FOREIGN KEY (`endpoint_group_id`) REFERENCES `endpoint_group` (`id`))<br>
<br>
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<br>
to say which one is better, is it worthwhile to move all of them to "ON DELETE CASCADE" or "ON DELETE RESTRICT"?<br>
<br>
<br>
[1] <a href="https://review.openstack.org/#/c/151931/5/keystone/contrib/endpoint_filter/migrate_repo/versions/002_add_endpoint_groups.py" target="_blank">https://review.openstack.org/#/c/151931/5/keystone/contrib/endpoint_filter/migrate_repo/versions/002_add_endpoint_groups.py</a><br>
<br>
Best Regards,<br>
Dave Chen<br>
<br>
<br>__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
<br></blockquote></div><br></div>