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 not jump next line 
Python :: find columns with missing values pandas 
Python :: write page source to text file python 
Python :: pandas transpose 
Python :: get column number in dataframe pandas 
Python :: python run shell command 
Python :: boto signed url 
Python :: make averages on python 
Python :: get first line of file python 
Python :: create fixtures django 
Python :: python xml parser 
Python :: SQLAlchemy query to dict 
Python :: pandas reset index without adding column 
Python :: python make sound when finished 
Python :: python chat application 
Python :: how to say something python 
Python :: pandas rename column by index 
Python :: python calculate derivative of function 
Python :: display 2d numpy array as image 
Python :: Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming 
Python :: python fill a list 
Python :: Python Creating string from a timestamp 
Python :: print subscript and superscript python 
Python :: console.log() python 
Python :: handle queries in listview django 
Python :: how to distribute a dataset in train and test using scikit 
Python :: python convert bool to string 
Python :: convert url to base64 image py 
Python :: pandas row from dict 
Python :: python file size in bytes 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =