kronoszx
3/24/2018 - 9:22 PM

Django on_delete

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

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

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

    models.SET_NULL
        Set the ForeignKey null; this is only possible if null is True.

    models.SET_DEFAULT
        Set the ForeignKey to its default value; a default for the ForeignKey must be set.

    models.SET()
        Set the ForeignKey to the value passed to SET(), or if a callable is passed in, the result of calling it. In most cases, passing a callable will be necessary to avoid executing queries at the time your models.py is imported: