我有以下模型,在Migrate
之后,我尝试通过管理页面添加数据
但是,我收到错误NOT NULL constraint failed: HVAC_chiller.basicinfo_ptr_id
参考其他stackoverflow,我明白了问题。但是,我找不到任何具有属性ptr的模型。
有谁知道我应该修改哪个属性?
models.py
class BasicInfo(models.Model):
title = models.CharField(max_length=100)
manufacturer = models.CharField(max_length=50, blank = True)
used_project = models.CharField(max_length=50, null=True,blank=True)
cost=models.IntegerField(null = True, blank = True)
url=models.URLField(null=True,blank=True)
comment=models.TextField(null=True,blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
class VRV(BasicInfo):
InletT = models.FloatField(blank=True)
OutletT = models.FloatField(blank=True)
Capacity = models.IntegerField(blank=True) # Reference capacity
COP = models.FloatField(blank=True) # Reference COP
class CapacityFunction(models.Model):
name=models.CharField(max_length=100, blank = True)
c1=models.FloatField()
c2=models.FloatField()
c3 = models.FloatField()
c4 = models.FloatField()
c5 = models.FloatField()
c6 = models.FloatField()
minX= models.FloatField(blank=True)
maxX = models.FloatField(blank=True)
minY = models.FloatField(blank=True)
maxY = models.FloatField(blank=True)
def __str__(self):
return self.name
class EIRofTemp(CapacityFunction):
pass
class EIRofPLR(models.Model):
name = models.CharField(max_length=100, blank=True)
c1=models.FloatField()
c2= models.FloatField()
c3 = models.FloatField()
c4 = models.FloatField(blank=True,null=True)
minX = models.FloatField(blank=True)
maxX = models.FloatField(blank=True)
def __str__(self):
return self.name
class Chiller(VRV):
CONDENSER_CHOICES = (
('WaterCooled','WaterCooled'),
('AirCooled', 'AirCooled'),
('EvaporativelyCooled','EvaporativelyCooled')
)
Condenser=models.CharField(max_length=15,choices=CONDENSER_CHOICES,default='Water')
CHWFlowRate=models.FloatField(blank=True,null=True)
CWFlowRate=models.FloatField(blank=True,null=True)
minPLR=models.FloatField(blank=True,null=True)
maxPLR=models.FloatField(blank=True,null=True)
optimumPLR=models.FloatField(blank=True,null=True)
minUnloadRatio=models.FloatField(blank=True,null=True)
CapacityFunction=models.OneToOneField(CapacityFunction,blank=True,null=True,on_delete=models.CASCADE,related_name='cap')
EIRofTemp=models.OneToOneField(EIRofTemp,blank=True,null=True,on_delete=models.CASCADE,related_name='eirtemp')
EIRofPLR = models.OneToOneField(EIRofPLR, blank=True,null=True, on_delete=models.CASCADE,related_name='eirplr')
答案 0 :(得分:1)
您尝试过多重继承。尝试使用ForeignKey()
class BasicInfo(models.Model):
title = models.CharField(max_length=100)
manufacturer = models.CharField(max_length=50, blank = True)
used_project = models.CharField(max_length=50, null=True,blank=True)
cost=models.IntegerField(null = True, blank = True)
url=models.URLField(null=True,blank=True)
comment=models.TextField(null=True,blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
class VRV(models.Model):
basic_info = models.ForeignKey(BasicInfo) # Foreign Key on BasicInfo model
InletT = models.FloatField(blank=True)
OutletT = models.FloatField(blank=True)
Capacity = models.IntegerField(blank=True)
COP = models.FloatField(blank=True)
class Chiller(models.Model):
CONDENSER_CHOICES = (
('WaterCooled','WaterCooled'),
('AirCooled', 'AirCooled'),
('EvaporativelyCooled','EvaporativelyCooled'))
vrv = models.ForeignKey(VRV) # Foreign Key of VRV model
Condenser=models.CharField(max_length=15, choices=CONDENSER_CHOICES, default='Water')
CHWFlowRate=models.FloatField(blank=True,null=True)
CWFlowRate=models.FloatField(blank=True,null=True)
minPLR=models.FloatField(blank=True,null=True)
maxPLR=models.FloatField(blank=True,null=True)
optimumPLR=models.FloatField(blank=True,null=True)
minUnloadRatio=models.FloatField(blank=True,null=True)
CapacityFunction=models.OneToOneField(CapacityFunction,blank=True,null=True,on_delete=models.CASCADE,related_name='cap')
EIRofTemp=models.OneToOneField(EIRofTemp,blank=True,null=True,on_delete=models.CASCADE,related_name='eirtemp')
EIRofPLR = models.OneToOneField(EIRofPLR, blank=True,null=True, on_delete=models.CASCADE,related_name='eirplr')
尝试使用标准的Django / Python语法约定。例如,