Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django on_delete options

#ONDELETE CASCADE
your_foreign_key_field = models.ForeignKey(Your_Reference_Model, on_delete=models.CASCADE)

#ONDELETE SET_NULL
your_foreign_key_field = models.ForeignKey(Your_Reference_Model, on_delete=models.SET_NULL)
Comment

django on-delete options

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.
Comment

on_delete django options

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

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

PREVIOUS NEXT
Code Example
Python :: python developer job description 
Python :: initialize variable python 
Python :: python beautifulsoup get attibute 
Python :: python squared 
Python :: pyqt5 buttons 
Python :: csv.dictreader 
Python :: python tkinter scrollbar 
Python :: how to make a calculator 
Python :: python input().strip() 
Python :: how to sum only the odd values in python 
Python :: python return double quotes instead of single 
Python :: python check if variable has value 
Python :: how to make a programming language in python 
Python :: opencv rgb to gray custom 
Python :: tkinter triangle 
Python :: how to get runtime of a function in python 
Python :: pytorch get tensor dimension 
Python :: optimization in python 
Python :: python infinite loop 
Python :: error aesthetics must be either length 1 or the same as the data (3) fill 
Python :: python data first column indices 
Python :: compare list and dataframe in pandas 
Python :: forward checking algorithm python 
Python :: code error correction 
Python :: sklearn pipeline with interactions python 
Python :: how to add twoo segmen time series in a single plot 
Python :: how to navigate to a sub html script selenium python 
Shell :: ubuntu XAMPP Starting Apache...fail 
Shell :: npm list global packages 
Shell :: check gnome version 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =