这是我的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
。但这究竟是什么意思,为什么我收到这条消息,我该怎么做才能让我不要求这条消息?
答案 0 :(得分:10)
删除/删除模型并进行迁移时会触发您收到的消息。
在大多数情况下,您可以安全地删除它们。但是,在某些情况下,这可能会导致数据丢失。如果其他模型具有已删除模型的外键,则这些对象也将被删除。
Here's the django ticket that requests to make deleting stale content types safer.
修改强>
正如@ x-yuri指出的那样,此票证已经修复并已在Django 1.11中发布。