2011-09-12 25 views
3

我重置之前加載夾具(參照Problems with contenttypes when loading a fixture in Django)CONTENTTYPES。[django的]錯誤:CONTENTTYPES不能復位

但CONTENTTYPES不能復位:

...project_dir > manage.py reset contenttypes

You have requested a database reset. This will IRREVERSIBLY DESTROY any data for the "contenttypes" application in the database "my_database". Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

Error: Error: contenttypes couldn't be reset. Possible reasons:

  • The database isn't running or isn't configured correctly.
  • At least one of the database tables doesn't exist.
  • The SQL was invalid.

Hint: Look at the output of 'django-admin.py sqlreset contenttypes'. That's the SQL this command wasn't able to run.

The full error: (1217, 'Cannot delete or update a parent row: a foreign key cons traint fails')

任何幫助將不勝感激。謝謝!

+0

可以在命令中輸入'django-admin.py sqlreset contenttypes'和看到的錯誤是有什麼呢? –

+0

對此有何見解?你有沒有設法解決這個問題? –

回答

0

在這個問題你貼有另一answer - 使用natural keys的燈具。

的錯誤「不能刪除或更新父行:traint失敗外鍵利弊」的意思是,因爲是指向該行另一對象的內容類型行不能刪除。例如。如果有任何非空白的通用外鍵關係就是這種情況。

如果你真的需要重置內容類型的應用程序,你可以得到所需要這個SQL命令並改變其使用CASCADE聲明。但是,這是危險,因爲它不僅會刪除內容類型,還會刪除其他表中指向內容類型的行。

所以我建議重新創建使用自然鍵燈具。