models.E006 in abstract parent model - Django 3.1

梦想的初衷 提交于 2021-01-05 11:23:27

问题


I have an abstract model and a few other classes that inherit from it.

# 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)

although my Parameter class is abstract, I get models.E006 error in python manage.py makemigrations script.

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'.

based on Abstract base classes and this question, if I inherit from an abstract base class, there should be no conflict in the name of the fields of various child classes with their parent (because it's abstract).

any ideas?


回答1:


The error is unrelated to the abstract base class.

The problem is the = integer when you define the IntegerField, which means the field is created twice.

Change:

data = integer = models.IntegerField(blank=True, null=True)`

to

data = models.IntegerField(blank=True, null=True)


来源:https://stackoverflow.com/questions/65343715/models-e006-in-abstract-parent-model-django-3-1

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