Django Models Deep Dive
Understanding on_delete BehaviourMediumMultiple Choice
3/5
MCQ — Relationships

Description

You have the following Django models:
class Author(models.Model):
    name = models.CharField(max_length=100)

class Book(models.Model):
    title = models.CharField(max_length=200)
    author = models.ForeignKey(Author, on_delete=???)
You want the following behaviour: when an Author is deleted, all their books should remain in the database but with `author` set to `NULL`. Which `on_delete` option achieves this?

Requirements

01Books must not be deleted when an Author is removed
02The author field on orphaned books should become NULL
03Consider which on_delete options Django provides

Select Your Answer