2

标题不清楚,我知道。
我想对我的应用程序进行单元测试,所以我写了一个我想执行的小测试。我启动了python manage.py test,但数据库中有一个错误:

The error was: ERREUR:  the relation « me_auth_emailuser » doesn't exists

Error in migration: authtoken:0001_initial
DatabaseError: ERREUR:  the relation « me_auth_emailuser » doesn't exists

(从法语翻译)
此表已使用南迁移。对于我的应用程序,我只使用:

python manage.py syncdb
python manage.py migrate me_auth
python manage.py migrate

我不明白发生了什么,因为使用这些命令我没有收到任何错误......有人可以帮助我吗?:)

4

1 回答 1

2

大概在某个时候你有一个关系me_auth_email_user,你不再有。我想如果你要创建一个新的数据库并运行,你会得到同样的错误:

python manage.py syncdb
python manage.py migrate

有两种解决方案:

  1. 不要在你的单元测试中使用 South (INSTALLED_APPS如果你正在测试,可以将它从你的测试中删除,如下所示,或者通过SOUTH_TESTS_MIGRATE = False在你的settings.py.
  2. 手动修复损坏的迁移。

在测试期间删除 South 的一种快速而简单的方法是在你的settings.py, 在你的正常INSTALLED_APPS设置下面有这样的东西:

import sys

if 'test' in sys.argv:
  INSTALLED_APPS = [app for app in INSTALLED_APPS if app != 'south']

一般来说,测试迁移是一件好事——你应该总是能够创建一个新的数据库并运行migrate——所以我强烈建议考虑选项 (2)。

于 2013-07-16T10:26:54.880 回答