我的测试不起作用。如果我尝试 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
最佳答案
据我所知,您必须编写一个自定义测试运行程序来有选择地将 --fake
添加到各个迁移中。
您可能应该修复您的数据库迁移 - 看起来您有两个迁移正在尝试创建相同的表。
South 希望在开始测试之前按顺序运行所有迁移,以建立初始数据库,但目前还无法做到这一点。
如果将其放入 settings.py
文件 ( reference ) 中,您可以完全禁用 South 进行单元测试:
SOUTH_TESTS_MIGRATE = False
如果您这样做,那么 Django 测试运行程序将仅根据您当前的模型创建测试数据库,而不是运行迁移来构建它。
关于python - 如何使用 migrate appname --fake 运行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14855777/