1

我正在将一个项目从使用 django-social-auth 移植到 python-social-auth。我按照文档中的说明进行操作,但是当我尝试运行项目的测试(./manage.py 测试)时,出现以下错误:

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 上使用的名称兼容,所以不需要迁移数据。

4

1 回答 1

4

遇到同样的问题。

即使 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 卸载

希望这可以帮助。

于 2014-02-21T17:49:07.617 回答