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

update the ForeignKey field for Django 2.0 #42

Open
wants to merge 3 commits into
base: 1.8
Choose a base branch
from

Conversation

christinesfkao
Copy link
Contributor

@christinesfkao christinesfkao commented Aug 29, 2018

ForeignKey is a Django field for defining a many-to-one relationship.

Up until Django 1.9 the ForeignKey field required a single argument: the model to map to.
Since Django 2.0 the ForeignKey field requires two positional arguments:

  • the model to map to
  • the on_delete argument

If without the second argument, error message shows:

File "~/lunch/lunch/stores/models.py", line 16, in MenuItem
    store = models.ForeignKey('Store', related_name='menu_items')
TypeError: __init__() missing 1 required positional argument: 'on_delete'

You can find more about on_delete by reading the documentation.

Reference: https://www.valentinog.com/blog/django-missing-argument-on-delete/

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

Successfully merging this pull request may close these issues.

1 participant