问题
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