我正在尝试通过扩展默认 django 用户来创建 UserProfile 模式。无法保存附加值,因为User has no user profile:RelatedObjectDoesNotExist
:
user = User.objects.create_user(username=username, password=password)
user.save()
print(fb_id)
user.userprofile.fb_id = fb_id
user.userprofile.save()
模态:
class UserProfile(models.Model):
user = models.OneToOneField(User)
fb_id = models.BigIntegerField(null=True, blank=True, default=0)
follows = models.ManyToManyField('self', related_name='followed_by', symmetrical=False)
无法理解为什么它是错误的以及如何以正确的方式做?姜戈 1.8