簡體   English   中英

Django在測試期間無法刷新數據庫

[英]Django can't flush database during tests

當我嘗試運行我的測試(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.

我在我們的項目中使用分區 ,這些分區是通過python函數動態生成的(所以我可以定期運行它)。 我沒有這些分區的任何模型。

syncdb觸發post_syncdb信號后調用分區維護功能(因此在設置測試數據庫時執行)。

如何讓Django清除其他表(分區)? 或者如何在運行測試時告訴Django使用CASCADE?

主要問題出現在我們改變M2M領域的關系的地方。 舊約束仍然存在,並且創建了新關系的新約束。 在Django 1.8中修復

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM