on_delete options django

There are seven possible actions to take when such event occurs:

CASCADE: When the referenced object is deleted, also delete the objects that have references to it 
  (when you remove a blog post for instance, you might want to delete comments as well). 
  SQL equivalent: CASCADE.
      
PROTECT: Forbid the deletion of the referenced object. 
  To delete it you will have to delete all objects that reference it manually. 
  SQL equivalent: RESTRICT.
    
RESTRICT: (introduced in Django 3.1) Similar behavior as PROTECT that matches SQL's RESTRICT more accurately. (See django documentation example)
SET_NULL: Set the reference to NULL (requires the field to be nullable). 
  For instance, when you delete a User, you might want to keep the comments he posted on blog posts, 
  but say it was posted by an anonymous (or deleted) user. 
  SQL equivalent: SET NULL.
    
SET_DEFAULT: Set the default value. SQL equivalent: SET DEFAULT.
    
SET(...): Set a given value. This one is not part of the SQL standard and is entirely handled by Django.
  
DO_NOTHING: Probably a very bad idea since this would create integrity issues in your database 
  (referencing an object that actually doesn't exist). SQL equivalent: NO ACTION.

3.71
6
Orome 95 points

                                    HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 0,
    "next": null,
    "previous": null,
    "results": []
}

3.71 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
on_delte django django delete options django model on_delete options django on delete option on delete option django django models on delete options django on_delete models on_delete method in django model on delete method in django model on delte django models on delete option in django models on delete in django on_delete in djanog models django on_delete=models. django on_delete documentation django models on_delete options on delete django fore on delete in django on delete options django on_deleete options django django on delete() on delete on django django on_delete function django on_delete default django on_delete how does it work on delete django models django on delete requried on_delete django options django on_delete delete on_delete set django on_delete options django FILeField cascade on delete example python django on_delete foreign key on_delete models python foreign keyon_delete models python on_delete in django on delete django options django choices on dlete django on delete cascade models.charfield max_length to_field django ondelete in django django models on-delete django models.cascade django related_name max_length django charfield django integer django models.SET_NULL django on_delete set() django on_delete set datetimefield django django to_fields charfield in django textfield django django models type of fields difference between models.set_null and on_delete on_delete models django django datetimefield django cascase django unique field django textfield django django delete cascade django model on_delete on_delete=models.set_null django emailfield django django models textfield default django models textfield how to interprete django on_delete python on_delete django on_delete models.cascade ondelete django django models types models textfield django model related_name django choice filed in django models on delete cascade django on_delete default django on deelete django cascade model django on_delete django cascade django positivesmallintegerfield on_delete models foreignkey django cascade dajngo cascade in django ondelete cascade django django cascade django email field django class text choices django db_index models django integer field django path field django fields blank django models.integer choices django on delete options fields in django have a field uniediable after first time django django models decimalfield blank django delete django django autofield textchoice django models.cascade django on_delete=models protect django models delete django django decimalfield django models booleanfield default false 2020 choices argument django model models.integerfield django field type django model data types on delelete django options django models.CharField DecimalField text django float field django model field note django models.ForeignKey on_delete django integer field models fields django blank in django model django on_delete models cascade django model feilds TextField options django setting on_delete django django auto_now django model number field django field.default django delete all django - on_delete django on delete django slugfield models.CharField django on_delete options django auto_now_add django filefield charfield django models.TextChoices max_digits django decimal field django 3 django text choices charfield django addition django date field django model field type django models on_delete IntegerChoices django cholestasis field in django null= django django models on delete site:https://docs.djangoproject.com/en/3.1/ imageField ImageField related_name django django model foreign key db_column django fields django datetimefield auto_now_add django integerchoices example django integerfield choices in django models model str fiels upload_to django floatfield django filefield django model django TextField positiveintegerfield django Choice fiels in the django django imagefield django on_delete cascade example django cascade on delete django slug field on_delete django fields in django models django models with default value django decimal field Text Choices django on delete django django project model fields django models default value does not exist reflect in db foreign key on delete django models.datefield django integerfield django integer choices django django field django models fields django models option models.textfield django model fileds models.cascade model fields django integer field in django models django model field django inttegerField with default django model fields positive interer field django integer field django Django choices django documemtation default value for boolean on_delete=models.CASCADE manytomanyfield limit_choices_to django uuid field model field django fields model.integerfield django TextChoices method django datefield binaryfield uuid django filefield upload_to django on_delete cascade models.set_null vs models.set_Cascade models.datetimefield django how to reference datetimefield modelfield in django form django durationfield on_delete=models.cascade in django use of on delete in django foreign key django model foreign key on delete django on_delete default on_delete django
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source