当我尝试运行我的测试(python manage.py test)时,我得到了:
CommandError: Database test_db couldn't be flushed. Possible reasons:
* The database isn't running or isn't configured correctly.
* At least one of the expected database tables doesn't exist.
* The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "install_location_2015_05_13" references "app".
HINT: Truncate table "install_location_2015_05_13" at the same time, or use TRUNCATE ... CASCADE.
我在项目中使用partitions,它是通过python函数动态生成的(所以我可以定期运行它)。我没有这些分区的任何模型。
在 syncdb 触发 post_syncdb 信号后调用分区维护功能(因此在设置测试数据库时执行)。
如何让Django清除其他表(分区)?要么 如何在运行测试时告诉Django使用CASCADE?