【问题标题】:Django 1.11 upgrade - object has no attribute 'password'Django 1.11 升级 - 对象没有属性“密码”
【发布时间】:2017-07-05 18:40:48
【问题描述】:

我在 Django 1.7 上运行良好。我正在尝试升级到 1.11。

我在 1.11 上遇到以下错误,我似乎找不到问题。

这是有问题的代码:

class Profile(models.Model):
    profile_id = models.CharField(max_length=50, null=True, unique=True, db_index=True)
    pet_shop_customer_id = models.CharField(max_length=40)
    django_user = models.OneToOneField(User, to_field='username', parent_link=True, null=True,
                                       db_column="django_username", default=None, db_index=True, db_constraint=False)

问题是当我打电话时:

profile = Profile.objects.get(profile_id='x')  # pulls a valid profile
print profile.django_user

我收到此错误:

异常值:

'Profile' object has no attribute 'password'

Exception Location:     /Users/../lib/python2.7/site-packages/django/db/models/fields/related_descriptors.py in <dictcomp>, line 291

【问题讨论】:

  • 你的django_user 字段有parent_link=TrueProfile 模型应该继承自 User 吗?
  • 谢谢。我没有注意到这一点。把它拿出来似乎可以解决它。

标签: python django django-models django-authentication


【解决方案1】:

正如@adrien 在评论中提到的那样,这就是问题所在。我必须将一对一字段中的 parent_link=True 删除给用户。

【讨论】:

    猜你喜欢
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 2021-09-23
    相关资源
    最近更新 更多