1

我的测试不起作用。如果我尝试 python manage.py test appname 我有这个错误:

! You *might* be able to recover with:   = DROP TABLE "appname_userprofile"; []
   = DROP TABLE "appname_table2"; []
   = DROP TABLE "appname_table3"; []

 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS (one that supports DDL transactions)
 ! NOTE: The error which caused the migration to fail is further up.
Error in migration: content:0015_initial
django.db.utils.DatabaseError: table "appname_userprofile" already exists

如何运行我python manage.py test appname

manage.py migrate appname --fake
4

1 回答 1

3

--fake据我所知,您必须编写一个自定义测试运行程序来选择性地添加到单个迁移中。

你可能应该修复你的数据库迁移——看起来你有两个试图创建同一个表的迁移。

South 希望在开始测试之前按顺序运行所有迁移,以建立一个初始数据库,而现在它无法做到这一点。

如果将其放入settings.py文件(参考)中,则可以完全禁用 South 进行单元测试:

SOUTH_TESTS_MIGRATE = False

如果你这样做了,那么 Django 测试运行器只会根据你当前的模型创建你的测试数据库,而不是运行迁移来构建它。

于 2013-02-13T15:32:33.310 回答