0

我正在尝试将 django auth ldap (v1.1.7) 与自定义用户模型一起使用,虽然我已经处理了所有其他事情,但我仍然遇到了一个熟悉的错误消息,我只是不知道如何修复。

运行python manage.py syncdb返回:

CommandError: One or more models did not validate:
django_auth_ldap.testprofile: 'user' defines a relation with the model 'auth.Use
r', which has been swapped out. Update the relation to point at settings.AUTH_US
ER_MODEL.

我的问题是 - 我在哪里可以找到django_auth_ldap.testprofile和更新关系以解决问题?

提前感谢您帮助我。

LE:好的,经过一番谷歌搜索后,我发现这个 testprofile 位于 django_auth_ldap/models.py 并得到这个:我搜索了我所有的文件并找到了该文件,将其修改为指向 settings.AUTH_USER_MODEL 并且我仍然收到相同的错误。

谁能帮我解决这个问题?

4

1 回答 1

1

这是models.py的一部分-django_auth_ldap

class TestProfile(models.Model):
    """
    A user profile model for use by unit tests. This has nothing to do with the
    authentication backend itself.
    """
    user = models.OneToOneField('auth.User')  # <-- here is the trouble
    is_special = models.BooleanField(default=False)
    populated = models.BooleanField(default=False)

除非您修复这部分代码并按照Django 文档中的说明进行操作,否则您无法修复它-

您应该使用 django.contrib.auth.get_user_model() 来引用用户模型,而不是直接引用 User。此方法将返回当前活动的用户模型 - 如果指定了自定义用户模型,则返回用户模型,否则返回用户。

而且我不建议您自己修改 3rd 方包。如果可以,请向开发人员建议更改,或向他们发送拉取请求。一旦它被接受,更新包。

于 2014-01-30T14:18:23.850 回答