Add on_delete to ForeignKey definitions.
Review Request #11988 — Created Jan. 24, 2022 and submitted
Django has made the
on_delete
argument toForeignKey
mandatory.
Until now, this has defaulted toCASCADE
, which makes it easy to
unintentionally delete things that shouldn't be deleted. Making it a
required argument forces developers to think about each model and how it
should behave.This change explicitly sets
on_delete
for every relation we have. Most
of these areCASCADE
, but the diff data ones areSET_NULL
because
those are effectively a one-to-many relation, and we don't want to
delete diff data that may be shared by other diffs.
Ran unit tests.
- Commits:
-
Summary ID 55595154ca3889f0a8493da16d79e2ff3eccad0d 1997c4e771a9be4ff6624852af91dc5b06731d33 - Diff:
-
Revision 2 (+386 -224)
Checks run (2 succeeded)
- Description:
-
Django has made the
on_delete
argument toForeignKey
mandatory.Until now, this has defaulted to CASCADE
, which makes it easy tounintentionally delete things that shouldn't be deleted. Making it a required argument forces developers to think about each model and how it should behave. + + This change explicitly sets
on_delete
for every relation we have. Most+ of these are CASCADE
, but the diff data ones areSET_NULL
because+ those are effectively a one-to-many relation, and we don't want to + delete diff data that may be shared by other diffs. - Commits:
-
Summary ID 1997c4e771a9be4ff6624852af91dc5b06731d33 a6eb4c8323c57a65ff0f425ab8ac8ec907436ea4 - Diff:
-
Revision 3 (+390 -224)