Python Django can';在测试期间刷新数据库
尝试运行测试(python manage.py test)时,我得到:Python Django can';在测试期间刷新数据库,python,django,postgresql,testing,Python,Django,Postgresql,Testing,尝试运行测试(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 in
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.
我在我们的项目中使用的是通过python函数动态生成的(因此我可以定期运行它)。我没有这些分区的任何模型
分区维护功能在syncdb触发post_syncdb信号后调用(因此在设置测试数据库时执行)
如何让Django清除附加表(分区)?或
我如何告诉Django在运行测试时使用CASCADE?主要问题发生在我们在M2M字段中更改关系的地方。保留旧约束,并为新关系创建新约束 对于Django==2.0.2me,我仍然会遇到这种情况,对于Django==3.1.2,我也会遇到这种情况