当前位置: 动力学知识库 > 问答 > 编程问答 >

postgresql - Postgres in django app queries using PK UUID fields INT rather then the UUID

问题描述:

Why is it that my model that has a UUID PK returns its INT representation during this lookup? This only happens on my dev server. Locally this works as desired.

class FooBar(models.Model):

foobar_id = models.UUIDField(

primary_key=True,

default=uuid.uuid4,

editable=False

)

self

<django.db.backends.utils.CursorDebugWrapper object at 0x7f4cc8f98d30>

sql

('SELECT DISTINCT "taggit_tag"."id", "taggit_tag"."name", '

'"taggit_tag"."slug" FROM "taggit_tag" INNER JOIN "taggit_taggeditem" ON ( '

'"taggit_tag"."id" = "taggit_taggeditem"."tag_id" ) WHERE '

'("taggit_taggeditem"."object_id" = %s AND '

'"taggit_taggeditem"."content_type_id" = %s)')

params

(216053040644727963891633708661715513721, 9)

Column | Type |

---------------+--------------------------+

exception_id | uuid |

The resulting error:

operator does not exist: uuid = numeric

LINE 1: ..."tag_id" ) WHERE ("taggit_taggeditem"."object_id" = 21605304...

The lookup should be a uuid against another uuid. Not numeric. Don't understand where or why it gets converted.

class GenericTaggedItemBase(ItemBase):

object_id = models.UUIDField(

verbose_name=_('Object id'),

db_index=True,

default=uuid.uuid4,

primary_key=True,

editable=False

)

content_type = models.ForeignKey(

ContentType,

verbose_name=_('Content type'),

related_name="%(app_label)s_%(class)s_tagged_items"

)

content_object = GenericForeignKey()

网友答案:

Your model's PK might be a UUID, but the object_id field that's part of the GenericForeignKey field in TaggedItem is still an integer.

There wouldn't really be a good way of fixing this without modifying the taggit app itself, unfortunately.

分享给朋友:
您可能感兴趣的文章:
随机阅读: