Django测试在Postgresql (8.4)上失败 - 刷新数据库导致错误

2 投票
1 回答
657 浏览
提问于 2025-04-17 01:41

我在用PostgreSQL数据库运行DJ测试时遇到了一个非常烦人的问题。测试开始运行,但在第一次数据库清空的时候就出错了,错误信息很奇怪:

..Error: Database dbname 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 "table_name" because it has pending trigger events

如果我把sqlflush的输出在pgAdmin里运行,它就能正常工作。

欢迎大家提供可能的原因。

更新:

好的,看来这其实不是Django的问题,而是和djangosanetesting的测试运行器有关。用默认的DJ测试运行器或者django-nose测试运行器就能正常工作。

1 个回答

1

好的,看起来这个问题其实不是出在Django上,而是和一个叫做 djangosanetesting 的测试工具有关,似乎它的刷新功能有点问题。目前我没有比直接使用 django-nose 测试工具更好的解决办法。

撰写回答