Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.2.3: Example 22.6: on_delete=SET_NULL requires null=True #221

Open
mschoettle opened this issue Mar 15, 2022 · 0 comments
Open

22.2.3: Example 22.6: on_delete=SET_NULL requires null=True #221

mschoettle opened this issue Mar 15, 2022 · 0 comments

Comments

@mschoettle
Copy link

Location within the Book

  • Chapter or Appendix: 22
  • Section: 2
  • Subsection: 3

Description

In Example 22.6 there are 3 model classes with a OneToOneField for user. I am trying something out for a project and defined a field like this which raises the following Django error:

some_app.SomeModel.user: (fields.E320) Field specifies on_delete=SET_NULL, but cannot be null.
app_1 | HINT: Set null=True argument on the field, or change the on_delete rule.

According to the documentation null=True is required for SET_NULL.

Possible Solutions

I suppose it would require null=True to be added to all three profiles but this would allow a profile to exist without the user.
Not sure if this would be a good idea, though.

Unless the example is purposefully kept small and this is up to the reader to decide how to deal with in the specific project.

Your full name so we can provide accurate credit within the book

Matthias Schoettle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant