What does on_delete do on Django models?

321    Asked by AmitSinha in Java , Asked on Jun 23, 2021
I'm quite familiar with Django but recently noticed there exist an on_delete=models.CASCADE option with the models, I have searched for the documentation for the same but couldn't find anything more than:

Changed in Django 1.9:

on_delete can now be used as the second positional argument (previously it was typically only passed as a keyword argument). It will be a required argument in Django 2.0.

an example case of usage is

from django.db import models 
class Car(models.Model): 
manufacturer = models.ForeignKey( 
'Manufacturer',
on_delete=models.CASCADE, 
)
# ... 
class Manufacturer(models.Model):
# ... 
pass

What does on_delete do? (I guess the actions to be done if the model is deleted)

What does models.CASCADE do? (any hints in the documentation)

What other options are available (if my guess is correct)?

Where does the documentation for this reside?

Answered by Bernadette Bond

Your Answer

Interviews

Parent Categories