尝试迁移时出现 "The following content types are stale and need to be deleted"。这是什么意思,我该如何解决?
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?
这是我的 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
模型中(所以如果有人能弄清楚为什么它说它说 'removing the field user from notification',那就太好了!)但是,当我继续尝试做 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
。但这到底是什么意思,为什么我会收到此消息以及如何才能使我不需要此消息?
当您 remove/delete 一个模型并进行迁移时,您收到的消息会被触发。
在大多数情况下,您可以安全地删除它们。但是,在某些情况下,这可能会导致数据丢失。如果其他模型有被移除模型的外键,这些对象也将被删除。
Here's the django ticket that requests to make deleting stale content types safer.
编辑
正如@x-yuri 指出的那样,此问题单已修复并已在 Django 1.11 中发布。
这是我的 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
模型中(所以如果有人能弄清楚为什么它说它说 'removing the field user from notification',那就太好了!)但是,当我继续尝试做 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
。但这到底是什么意思,为什么我会收到此消息以及如何才能使我不需要此消息?
当您 remove/delete 一个模型并进行迁移时,您收到的消息会被触发。
在大多数情况下,您可以安全地删除它们。但是,在某些情况下,这可能会导致数据丢失。如果其他模型有被移除模型的外键,这些对象也将被删除。
Here's the django ticket that requests to make deleting stale content types safer.
编辑
正如@x-yuri 指出的那样,此问题单已修复并已在 Django 1.11 中发布。