简体   繁体   English

为什么我在 python 3 中出现“function upper(bytea)”错误?

[英]Why am I getting 'function upper(bytea)' error in python 3?

Currently I am working to convert my py-2 project in py-3 & during this conversion I have faced below kind of error.目前我正在努力将我的 py-2 项目转换为 py-3 并且在此转换期间我遇到了以下错误。

Partner.objects.filter(name__iexact = name_kv).count()

When I am running above query in py2 it working perfectly & getting output '0', means getting empty list.当我在 py2 中运行上面的查询时,它工作得很好并且得到 output '0',意味着得到空列表。

When I am running above query in py3 it showing below kind of error.当我在 py3 中运行上面的查询时,它显示以下错误。

django.db.utils.ProgrammingError: function upper(bytea) does not exist
LINE 1: ...alse AND UPPER("partners_partner"."name"::text) = UPPER('\x4...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

I have searched lot online & SO other questions but but not able to find any solution.我在网上搜索了很多其他问题,但找不到任何解决方案。

I figured out that it must have been python version problem & I am getting above error when my ORM query does not have any records .我发现它一定是 python 版本问题,当我的 ORM 查询没有任何记录时,我遇到了错误

Try to convert your variable name_kv to string type using str(name_kv) .尝试使用str(name_kv)将变量name_kv转换为字符串类型。

Update your query like Partner.objects.filter(name__iexact = str(name_kv)).count() .更新您的查询,例如Partner.objects.filter(name__iexact = str(name_kv)).count()

You are getting error because variable containing byte type data so converting byte data to string type may solve your problem.您收到错误是因为变量包含字节类型数据,因此将字节数据转换为字符串类型可能会解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM