Getting a “The following content types are stale and need to be deleted” when trying to do a migrate. What does this mean, and how can I solve it?

懵懂的女人 提交于 2020-01-01 08:25:11

问题


This is my 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

When I do python manage.py makemigrations, this is what it says:

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

First, it's weird that it says Remove field user from notification because user is still in my Notiication model (so if anyone can figure out why it says that it say 'removing the field user from notification', that would be great!) but nonetheless, when I move on and try to do python manage.py migrate I get this message:

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

I typed no. But what exactly does this mean, why am I getting this message and how do I make it so that I don't require this message?


回答1:


The message you get is triggered when you remove/delete a model and do a migration.

In most cases, you can delete them safely. However, in some cases this might result to data loss. If other models have a foreign key to the removed model, these objects will also be deleted.

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

EDIT

As @x-yuri pointed, this ticket has been fixed and has been released in Django 1.11.



来源:https://stackoverflow.com/questions/34057468/getting-a-the-following-content-types-are-stale-and-need-to-be-deleted-when-tr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!