【发布时间】: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=True。Profile模型应该继承自User吗? -
谢谢。我没有注意到这一点。把它拿出来似乎可以解决它。
标签: python django django-models django-authentication