我有一个抽象模型和一些继承自它的其他类。
# models.py
class Parameter(models.Model):
data = integer = models.IntegerField(blank=True, null=True)
class Meta:
abstract = True
class Temperature(Parameter):
received_timestamp = models.DateTimeField(default=datetime.now, blank=True)
class Ph(Parameter):
received_timestamp = models.DateTimeField(default=datetime.now, blank=True)
尽管我的 Parameter
类是抽象的,但我在 python manage.py makemigrations
脚本中收到 models.E006
错误。
graphs.Temperature.data: (models.E006) The field 'data' clashes with the field 'data' from model 'graphs.temperature'.
graphs.Ph.data: (models.E006) The field 'data' clashes with the field 'data' from model 'graphs.ph'.
基于Abstract base classes还有这个question ,如果我从抽象基类继承,则各个子类的字段名称与其父类不应该发生冲突(因为它是抽象的)。
有什么想法吗?
最佳答案
该错误与抽象基类无关。
问题在于定义IntegerField
时的=integer
,这意味着该字段被创建了两次。
更改:
data = integer = models.IntegerField(blank=True, null=True)`
至
data = models.IntegerField(blank=True, null=True)
关于python-3.x - 抽象父模型中的 models.E006 - Django 3.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65343715/