63
-
CASCADE
Cascade deletes. Django emulates the behavior of the
SQL constraint ON DELETE CASCADE
and also deletes the object
containing theForeignKey
. -
PROTECT
Prevent deletion of the referenced object byraising
ProtectedError
, a subclass ofdjango.db.IntegrityError
.
the things get deleted because once you change your model you need to do makemigrations
and migrate
to see the change.
28
For on_delete=models.CASCADE
:
You have 2 models i.e., Car and Company. You delete the company, you also delete the cars made by that company.
For on_delete=models.PROTECT
:
You have 2 models. Car and Company. You delete the company, Django says, Hold up. Canβt do it β¦ So everything remains.
- [Django]-Change a Django form field to a hidden field
- [Django]-"Models aren't loaded yet" error while populating in Django 1.8 or later
- [Django]-Alowing 'fuzzy' translations in django pages?
Source:stackexchange.com