删除未使用的模型,陈旧的内容类型提示 [英] Deleting unused Models, stale content types prompt

查看:351
本文介绍了删除未使用的模型,陈旧的内容类型提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Django网站中删除不必要的表格和模型。我已经在迁移之前删除了所有foriegn关键引用.DeleteModel(...)被调用,但是当我运行迁移时,我仍然收到以下提示:


以下内容类型陈旧,需要删除:

  myapp | MyDeletedModel 

通过外键与这些内容类型相关的任何对象也将$ b​​ $ b删除。您确定要删除这些内容类型吗?如果
不确定,请回答否。

 输入是继续,或否取消:是


我很困惑为什么我收到此提示有没有办法,我可以停止这个提示显示什么时候上线?我们使用CI环境,我们没有用户可以回答是或否



谢谢

解决方案

contenttypes框架包含对模型表的引用。在这种情况下,您对您刚才删除的表有一个过时的引用。完全保存以回答并删除陈旧的内容类型。如果您重命名了一个指向它的 GenericForeignKey 的表,那将是一个不同的故事,在这种情况下,其他对象将有一个 ForeignKey ContentType ,删除将沿着这些关系级联。



在现场环境中,您可以通过 - noinput 选项来保留此提示。但是,它将默认为 no 。在周围有一些陈旧的内容通常不是一个问题。


I am removing an unnecessary table and model from our Django website. I have removed all foriegn key references before the migrations.DeleteModel(...) is called, but I still am receiving the following prompt when I run the migration:

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

myapp | MyDeletedModel

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? If you're unsure, answer 'no'.

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

I am confused why I am receiving this prompt is there a way I can stop this prompt from showing when we go live? we use a CI environment where we do not have users available to answer "yes" or "no"

Thanks

解决方案

The contenttypes framework contains references to model tables. In this case, you have a stale reference to the table you just deleted. It is perfectly save to answer yes and remove the stale contenttype. It would be a different story if you renamed a table that had a GenericForeignKey pointing to it, in which case other objects would have a ForeignKey to that ContentType, and the delete would cascade along those relations.

In a live environment, you can pass the --noinput option to surpress this prompt. However, it will default to no. It's usually not really a problem to have some stale contenttypes around.

这篇关于删除未使用的模型,陈旧的内容类型提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆