获取"以下内容类型陈旧,需要删除"当试图进行迁移时。这意味着什么,我该如何解决?

时间:2015-12-03 03:39:26

标签: django django-models django-migrations django-contenttypes

这是我的models.py:

class Notification(models.Model):
    user = models.ForeignKey(User)
    createdAt = models.DateTimeField(auto_now_add=True, blank=True)
    read = models.BooleanField(default=False, blank=True)

    class Meta:
        abstract = True

class RegularNotification(Notification):
    message = models.CharField(max_length=150)
    link = models.CharField(max_length=100)

class FNotification(Notification):
    # same as Notification
    pass

当我python manage.py makemigrations时,这就是它所说的:

Migrations for 'CApp':
  0019_auto_20151202_2228.py:
    - Create model RegularNotification
    - Create model FNotification
    - Remove field user from notification
    - Add field f_request to userextended
    - Delete model Notification

首先,它说Remove field user from notification很奇怪,因为user仍然在我的Notiication模型中(所以如果有人能弄清楚为什么它说它说'&# 39;从通知'中删除字段用户,这会很棒!)但是,当我继续前进并尝试python manage.py migrate时,我收到此消息:

Applying CMApp.0019_auto_20151202_2228... OK
The following content types are stale and need to be deleted:

    CApp | notification

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: no

我输入了no。但这究竟是什么意思,为什么我收到这条消息,我该怎么做才能让我不要求这条消息?

1 个答案:

答案 0 :(得分:10)

删除/删除模型并进行迁移时会触发您收到的消息。

在大多数情况下,您可以安全地删除它们。但是,在某些情况下,这可能会导致数据丢失。如果其他模型具有已删除模型的外键,则这些对象也将被删除。

Here's the django ticket that requests to make deleting stale content types safer.

修改

正如@ x-yuri指出的那样,此票证已经修复并已在Django 1.11中发布。