- 1 min

Use one-to-one relationships in Django2.0 models

Error message

 File "/Users/topaz/Desktop/Project/PWO/models.py", line 110, in UserProfile
 user = models.OneToOneField(User)
 TypeError: __init__() missing 1 required positional argument: 'on_delete'

Troubleshooting

 1.Error throwing line
 user = models.OneToOneField(User)

 2.Add models.CASCADE
 user = models.OneToOneField(User,models.CASCADE)

Reason:

 The Django1.8 version was used for application before, the upgraded version Django2.0 has changed, need to set 'on_delete'= models.CASCADE.
Topaz

Topaz

Always keep learning.

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo