1

它因许多与相关名称相关的问题而失败。当然,在运行实际的开发服务器(使用./manage.py runserver)时不会发生这种情况,我猜模型可能会生成两次?我正在运行 psycopg2 2.4.1,这是我的测试输出:

(venv)lacrymology@Roller:boilerplate$ ./manage.py test
Creating test database for alias 'default'...
Error: One or more models did not validate:
l10n.address: Accessor for field 'user_shipping' clashes with related field 'User.shipping_address'. Add a related_name argument to the definition for 'user_shipping'.
l10n.address: Reverse query name for field 'user_shipping' clashes with related field 'User.shipping_address'. Add a related_name argument to the definition for 'user_shipping'.
l10n.address: Accessor for field 'user_billing' clashes with related field 'User.billing_address'. Add a related_name argument to the definition for 'user_billing'.
l10n.address: Reverse query name for field 'user_billing' clashes with related field 'User.billing_address'. Add a related_name argument to the definition for 'user_billing'.
custom_registration.profile: Accessor for field 'user' clashes with related field 'User.profile'. Add a related_name argument to the definition for 'user'.
custom_registration.profile: Reverse query name for field 'user' clashes with related field 'User.profile'. Add a related_name argument to the definition for 'user'.
addressmodel.address: Accessor for field 'user_shipping' clashes with related field 'User.shipping_address'. Add a related_name argument to the definition for 'user_shipping'.
addressmodel.address: Reverse query name for field 'user_shipping' clashes with related field 'User.shipping_address'. Add a related_name argument to the definition for 'user_shipping'.
addressmodel.address: Accessor for field 'user_billing' clashes with related field 'User.billing_address'. Add a related_name argument to the definition for 'user_billing'.
addressmodel.address: Reverse query name for field 'user_billing' clashes with related field 'User.billing_address'. Add a related_name argument to the definition for 'user_billing'.
profiles.profile: Accessor for field 'user' clashes with related field 'User.profile'. Add a related_name argument to the definition for 'user'.
profiles.profile: Reverse query name for field 'user' clashes with related field 'User.profile'. Add a related_name argument to the definition for 'user'.
4

2 回答 2

1

您的 test.py 很可能会导入一个不在 INSTALLED_APP 内但有一些模型字段指向碰撞模型的应用程序。尝试在 test.py 中导入但不在 INSTALLED_APPS 中的应用程序中grep user_shipping ,并替换它。

./manage.py validate,将在内部调用./manage.py runserver,仅检查从 INSTALLED_APP 内的应用程序加载的模型,因此运行 devserver 时没有错误。但是,test.py 中的导入会导致加载额外模型的未安装应用程序(如果有),然后会发生冲突。

于 2012-04-08T10:26:04.010 回答
0

这是 django-shop 测试的问题,如评论中所述:创建测试数据库时 Django 测试失败

如果不更改应用程序的代码,我找不到解决办法,所以我最终只是测试了我自己的应用程序(运行./manage.py test myapp而不是./manage.py test

于 2014-01-08T14:17:05.040 回答