在我的模型中,我必须有2个相同模型的外键。我尝试了相关名称,因此makemigrations可以正常工作。但是当我尝试迁移时,它会抛出错误并说
django.db.utils.ProgrammingError: column "service_requested_by_id" cannot be cast automatically to type uuid
HINT: You might need to specify "USING service_requested_by_id::uuid".
我的模特
class Schedule(BaseModel):
project = models.ForeignKey("projects.Project",null=True,blank=True)
description = models.TextField(blank=True,null=True)
vehicle = models.ForeignKey("logistics.Vehicle",null=True,blank=True)
driver = models.ForeignKey("staffs.Staff",related_name='driver',blank=True,null=True)
service_requested_by = models.ForeignKey("staffs.Staff",related_name='service_requested_by',blank=True,null=True)
start_time = models.DateTimeField(null=True,blank=True)
end_time = models.DateTimeField(null=True,blank=True)
is_deleted = models.BooleanField(default=False)
starting_km = models.DecimalField(null=True,blank=True,default=0,decimal_places=0, max_digits=15,validators=[MinValueValidator(Decimal('0'))])
completed_km = models.DecimalField(null=True,blank=True,default=0,decimal_places=0, max_digits=15,validators=[MinValueValidator(Decimal('0'))])
travelled_km = models.DecimalField(null=True,blank=True,default=0,decimal_places=0, max_digits=15)
class Meta:
db_table = 'schedule'
verbose_name = _('schedule')
verbose_name_plural = _('schedules')
ordering = ('vehicle',)
class Admin:
list_display = ('vehicle',)
def __unicode__(self):
if self.vehicle:
return self.vehicle.name
else:
return str(self.project)
在我添加service_requested_by字段之前,一切正常。任何提示我可能在做错什么吗?除了此代码外,我还需要发布其他内容吗?
答案 0 :(得分:0)
好的,发生错误是因为我将列service_requested_by
的类型从textinput更改为外键。它把整个事情搞砸了。我需要做的是创建另一个具有不同名称的列,并使旧列保持原样,而不更改其类型。现在一切正常。