gpt4 book ai didi

python - Django 在测试期间无法刷新数据库

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:42 25 4
gpt4 key购买 nike

当尝试运行我的测试(python manage.py 测试)时,我得到:

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?

最佳答案

主要问题发生在我们改变 M2M 领域的关系的地方。保留旧约束并为新关系创建新约束。 Fixed in Django 1.8

关于python - Django 在测试期间无法刷新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30228609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com