删除陈旧的ContentTypes的最干净方法?

jam*_*jar 1 django django-models django-migrations

我想摆脱运行迁移时收到的以下消息:

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?
Run Code Online (Sandbox Code Playgroud)

在迁移中对删除或不删除的决定进行编码似乎更干净。

在迁移过程中检测和删除过时的ContentType的最干净方法是什么?如果自动创建 ContentType,为什么不自动完成?

小智 5

试试这个安全删除

python manage.py remove_stale_contenttypes
Run Code Online (Sandbox Code Playgroud)


Seb*_*ner 0

迁移数据库时,您可以像这样--noinput添加manage.py

manage.py migrate --noinput
Run Code Online (Sandbox Code Playgroud)

这样,就不会询问用户。