【发布时间】:2021-05-13 19:47:06
【问题描述】:
我在过滤我的 postgresql 上的数据时遇到了这个错误,它说错误来自这一行 .filter(bene_id='31452')。我一直在 Django 中使用两个表。我认为问题出在我的运营商 = 上,因为 id 是整数,但问题是我应该如何以及在该运营商中替换什么?
我尝试放置双 qoute、单 qoute 甚至没有像 .filter(bene_id="31452") 、.filter(bene_id=31452) 、.filter(bene_id='31452') 这样的元素。但似乎错误尚未解决。如果有人能弄清楚我做错了什么,那就太好了。提前非常感谢你
错误
LINE 1: ...2_benes_status" WHERE "b2_benes_status"."bene_id" = 31452 L...
^
HINT: No operator matches the given name and argument types. You might need
to add explicit type casts.
views.py
Testing = B2BenesStatus.objects.using('matchy_data').filter(bene_id='31452')
Models.py
class B2BenesStatus(models.Model):
datetime = models.DateTimeField(blank=True, null=True)
value = models.BooleanField(blank=True, null=True)
remarks = models.TextField(blank=True, null=True)
bene_id = models.IntegerField(blank=True, null=True)
stat_cat_id = models.IntegerField(blank=True, null=True)
updated_by_id = models.IntegerField(blank=True, null=True)
class Meta:
managed = False
db_table = 'b2_benes_status'
Settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'payroll',
'USER':'root',
'PASSWORD':'',
'HOST':'localhost',
'PORT':'3306',
},
'matchy_data': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'matchy_data',
'USER':'postgres',
'PASSWORD':'samplee',
'HOST':'localhost',
'PORT':'5432',
},}
【问题讨论】:
-
将查找中的
id更改为整数。 stackoverflow.com/questions/3739808/… -
@PacketLoss 但在我的模型中它已经设置为 integerFiled
bene_id = models.IntegerField(blank=True, null=True),您的意思是应该将其更改为 TextField 吗? -
我认为问题出在我的操作员
=上,因为 id 是整数,但问题是我应该如何以及在该操作员中替换什么? -
ORM 查询正确。不要使用 qoutes,因为它是整数字段。我建议重试没有 qoutes 的代码。我没有使用过第二个数据库和 postgresql,所以如果没有任何工作(并且你有时间),你可以在默认数据库中尝试一个具有相同字段的测试模型并尝试这个 Testing = B2BenesStatus.objects.filter(bene_id=31452)跨度>