如何将django uuid转换为注释的QuerySet中的整数?
我正在尝试将UUID转换为注释中的整数。
因此:
Item.objects.values_list('pk', flat=True).annotate(
int_of_pk=int('pk')
)
哪个引发错误:
valueerror:base 10:'pk'
or for int()的文字无效
或类似:
from django.db.models import IntegerField
from django.db.models.functions import Cast
Item.objects.values_list('pk', flat=True).annotate(
int_of_pk=Cast('pk', output_field=IntegerField())
)
哪个抛出错误:
File "/path/ve/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.CannotCoerce: cannot cast type uuid to integer
LINE 1: ...em"."uuid", ("item"."uuid")::integer ...
^
有什么想法弹出您吗?
I'm trying to convert UUIDs to integers within an annotate.
So like:
Item.objects.values_list('pk', flat=True).annotate(
int_of_pk=int('pk')
)
which throws error:
ValueError: invalid literal for int() with base 10: 'pk'
or like:
from django.db.models import IntegerField
from django.db.models.functions import Cast
Item.objects.values_list('pk', flat=True).annotate(
int_of_pk=Cast('pk', output_field=IntegerField())
)
which throws error:
File "/path/ve/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.CannotCoerce: cannot cast type uuid to integer
LINE 1: ...em"."uuid", ("item"."uuid")::integer ...
^
Any ideas pop out at you?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论