python - 从 django-social-auth 移植到 python-social-auth 时,现场用户的访问器发生冲突

标签 python django authentication django-socialauth python-social-auth

我正在将一个项目从使用 django-social-auth 移植到 python-social-auth。我关注了instructions在文档中,但是当我尝试运行项目的测试 (./manage.py test) 时,出现以下错误:

Creating test database for alias 'default' ...
CommandError: One or more models did not validate:
default.usersocialauth: Accessor for field 'user' clashes with related field 'User.social_auth'. Add a related_name argument to the definition for 'user'.
default.usersocialauth: Reverse query name for field 'user' clashes with related field 'User.social_auth'. Add a related_name argument to the definition for 'user'.

./manage.py syncdb 和 ./manage migrate 工作正常,正如预期的那样,因为(如文档所述),python-social-auth 中的模型表名被定义为与 django-social 上使用的表名兼容-auth,所以不需要迁移数据。

最佳答案

遇到同样的问题。

即使 django-social-auth 库已从 INSTALLED_APPS 中删除,django 仍然发现冲突,因为 django-social-auth 和 python-social-auth 使用具有相同 related_name 参数的相同外键。

要确切知道 python-social-auth 与哪个模型发生冲突,请在其中放置一个断点

get_validation_errors (validation.py)

第 148 和 150 行

for r in rel_opts.get_all_related_objects():
    if r.field is not f:
        if r.get_accessor_name() == rel_name:
            e.add(opts, "Accessor for field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'." % (f.name, rel_opts.object_name, r.get_accessor_name(), f.name))
        if r.get_accessor_name() == rel_query_name:
            e.add(opts, "Reverse query name for field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'." % (f.name, rel_opts.object_name, r.get_accessor_name(), f.name))

查看“r”变量将揭示发生冲突的相关对象。

从系统中完全删除库 django-social-auth 解决了这个问题。

因为最初是用easy_install安装的,所以我用rm -rf把它从site-packages中去掉了,但是也记得去掉easy_install.pth中的名字

你也可以使用pip卸载

希望这对您有所帮助。

关于python - 从 django-social-auth 移植到 python-social-auth 时,现场用户的访问器发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21293152/

相关文章:

python - 时区和本地化

python - 如何从全局设置模块在 Django 中设置特定设置

java - Waffle JAAS 认证

Python opencv子进程写入返回损坏的管道

python - 使用 Python 中的 xml 子对象、ElementTree

python - 安装 django 数据库日志

php - 可以一起使用 Zend_Http_Client() 和 Zend_Rest_Client()

java - RESTEasy java 中的用户登录认证

python - 如何在不等待的情况下调用异步函数?

python - Enthought Python 发行版包含 pyhdf 和 HDF 4