Django:提示:没有与给定名称和参数类型匹配的运算符。您可能需要添加显式类型转换

2024-09-27 21:33:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道为什么会显示这个错误,我一直在使用Postgresql,并且我观察到当我在我的模型上使用IntegerField时会发生这个错误,比如这个 b2_sacnumber_id = models.IntegerField(blank=True, null=True),或者甚至在本地数据库中使用Integer字段。即使我在我的模型中使用了Intererfiled,是否有任何解决方案可以获得该值?我是新来的博士后,谁能给我解释一下这一点吗?这对我真的很有帮助

错误

LINE 1: ...sac_forms" WHERE "b2_sac_forms"."b2_sacnumber_id" IN (31718,...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

queryviews.py

sample = ['31718','47060']
Sac_forms = list(B2SacForms.objects.using('matchy_data').values_list('b2_id', flat=True).filter(b2_sacnumber_id__in=sample))

我尝试的更改值sample像这样sample = ['31718','47060']sample = ["31718","47060"] ,甚至我尝试了sample = [31718,47060],但仍然出现了错误

models.py

class B2SacForms(models.Model):
  b2_id = models.IntegerField(blank=True, null=True)
  b2_sacnumber_id = models.IntegerField(blank=True, null=True)
  date = models.DateField(blank=True, null=True)
  generated_id = models.IntegerField(blank=True, null=True)

class Meta:
    managed = False
    db_table = 'b2_sac_forms'

Tags: samplepy模型idtruemodels错误forms

热门问题