django model.ForeignKey.on_delete

https://docs.djangoproject.com/en/4.2/ref/models/fields/#django.db.models.ForeignKey.on_delete

The possible values for on_delete are found in django.db.models:

  • CASCADE

    Cascade deletes. Django emulates the behavior of the SQL constraint ON DELETE CASCADE and also deletes the object containing the ForeignKey.

    Model.delete() isn’t called on related models, but the pre_delete and post_delete signals are sent for all deleted objects.

  • PROTECT

    Prevent deletion of the referenced object by raising ProtectedError, a subclass of django.db.IntegrityError.

  • RESTRICT

    Prevent deletion of the referenced object by raising RestrictedError (a subclass of django.db.IntegrityError). Unlike PROTECT, deletion of the referenced object is allowed if it also references a different object that is being deleted in the same operation, but via a CASCADE relationship.