2016-08-31 30 views
1

我想擺脫後續消息運行的遷移時,我得到的:最簡單的方法來刪除陳舊的ContentTypes?

The following content types are stale and need to be deleted: 

    appname | modelname 

Any objects related to these content types by a foreign key will also 
be deleted. Are you sure you want to delete these content types? 

這似乎更清潔編碼爲刪除或遷移不能刪除的決定。

作爲遷移的一部分,檢測和刪除過時的ContentType的最簡潔方法是什麼?如果ContentTypes爲created automatically,爲什麼不自動完成?

+1

如果[通用關係](https://docs.djangoproject.com/en/1.9/ref/contrib/contenttypes/#generic-relations)中使用了內容類型,則刪除它們將觸發'on_delete'動作這些模型中的外鍵可能會導致數據丟失 - 任何自動操作都應該不惜一切代價避免。創建內容類型不會導致數據丟失,因此自動執行是安全的。 – knbk

+0

在普通關係中是否無法檢測內容類型是否被使用? – jamjar

+0

可能相關:http://stackoverflow.com/questions/18869414/can-stale-content-types-be-automatically-deleted-in-django –

回答

0

當遷移數據庫,你可以添加到--noinputmanage.py如此:

manage.py migrate --noinput 

這樣,用戶不會被要求。

相關問題