【发布时间】:2016-02-16 18:11:37
【问题描述】:
假设我有以下基本模型:
class human(models.Model):
gender = models.BooleanField()
age = models.IntegerField()
name = models.CharField(max_length=200)
还有两个继承它的模型:
class superhero(human):
can_fly = models.BooleanField()
class villain(human):
fingerprint = models.ImageField()
在我的开发过程中的某个时候,我意识到我实际上并不直接需要人类课程。我只需要它是一组超级英雄和反派模型的模板参数。如果现在我去人类Meta 类并设置abstract=True 并像这样更改我的模型:
class human(models.Model):
gender = models.BooleanField()
age = models.IntegerField()
name = models.CharField(max_length=200)
class Meta:
abstract = True
class superhero(human):
can_fly = models.BooleanField()
class villain(human):
fingerprint = models.ImageField()
尝试进行迁移和迁移会引发以下错误
'superhero' 类中的本地字段 u'gender' 与基类 'human' 中类似名称的字段发生冲突
如何在不直接修改数据库的情况下切换到抽象类来保留所有迁移?
【问题讨论】:
标签: python django django-models abstract-class django-migrations