Provide an equivalent for 'ON DELETE' and friends
|Reported by:||ubernostrum||Owned by:||nobody|
|Cc:||petertripp@…, gabor@…, gonz||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: cascade, restrict, set_null, 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.
Change History (18)
comment:6 Changed 10 years ago by Simon G. <dev@…>
- Triage Stage changed from Unreviewed to Design decision needed