Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

what does on_delete do on Django models?

Asked by Amit Sinha Jun 23, 2021 600 views 1 answer
Share

About this question

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?

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.