Provide an equivalent for 'ON DELETE' and friends
|Reported by:||James Bennett||Owned by:||nobody|
|Cc:||petertripp@…, gabor@…, Gonzalo Saavedra||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
A couple threads on django-users have asked about deleting an object while preserving related objects, preferably by setting their foreign key fields to NULL, but AFAIK we don't expose that functionality in any way.
So, a proposed enhancement to model definitions.
ForeignKeyField should take two extra optional arguments:
on_delete -- value is one of:
set_default. If it's
set_default, a default value must be supplied. I'm thinking we can get by with just
restrict and not also
no_action, but open to arguments about it.
on_update -- same as above.
These constraints should be output in the SQL for the databases which support them, but either way they should always be respected by Django.