kev*_*kev 5 python testing django postgresql
当尝试运行测试(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.
Run Code Online (Sandbox Code Playgroud)
我在我们的项目中使用的分区是通过python函数动态生成的(因此我可以定期运行它)。我没有这些分区的任何模型。
在syncdb触发post_syncdb信号后调用分区维护功能(因此在建立测试数据库时执行该信号)。
如何使Django清除其他表(分区)?或如何在运行测试时告诉Django使用CASCADE?
小智 0
主要问题发生在我们改变 M2M 领域的关系时。旧的约束仍然存在,并为新关系创建了新的约束。已在 Django 1.8 中修复