What is on_delete used in django's model?

About on_delete used in djnago model

Regarding the title, I have a question that I encountered while studying a book.

The actual code looked like this:

python:django.models.py



class Test_Model:
    user = models.ForeignKey(CustomUser, verbose_name='user', on_delete=models.PROTECT, null=True)

When I looked it up, it was an indispensable item when linking models from django 2.0. The meaning seems to be ** what to do with the associated object when the referenced object is deleted **.

There are the following types of model. ・ CASCADE Delete all associated objects

・ PROTECT Cannot be deleted if there is an associated object

・ SET_NULL The object remains, but the corresponding item becomes Null

・ SET_DEFAULT The object will remain and the corresponding item will have a default value.

・ SET () The object can set the function to the remaining corresponding item

・ DO_NOTHING Do nothing.

If you don't decide how to handle it properly ...

Reference site https://djangobrothers.com/blogs/on_delete/

Recommended Posts

What is on_delete used in django's model?
What is Python? What is it used for?
What is labeling in financial forecasting?
What is "mahjong" in the Python library? ??
Benefits of using slugfield in Django's model
What is namespace
What is a dog? Django--Create a custom user model
What is copy.copy ()
Link the list_display item in Django's Model Admin
What is "functional programming" and "object-oriented" in Python?
What is Django? .. ..
What is dotenv?
What is POSIX?
What is wheezy in the Docker Python image?
What is Linux
What is klass?
If you specify a foreign key in Django's model change, you need to specify on_delete.
What is SALOME?
What is Linux?
What is python
What is hyperopt?
Make any key the primary key in Django's model
Search for yourself from methods in Django's model
What is Linux
What is a dog? Django--Create a custom user model 2
What is pyvenv
What is __call__
What is Linux
What is Python
What is the domain attribute written in Plotly's Layout?
What is a distribution?
What is Piotroski's F-Score?
What is Raspberry Pi?
[Python] What is Pipeline ...
What is a terminal?
[PyTorch Tutorial ①] What is PyTorch?
What is hyperparameter tuning?
Model changes in Django
What is JSON? .. [Note]
What is a pointer?
What is ensemble learning?
What is TCP / IP?
What is Python's __init__.py?
What is an iterator?
What is UNIT-V Linux?
[Python] What is virtualenv
What is machine learning?