为什么我的具有UUID PK的模型在此查找期间返回其INT表示?这只发生在我的开发服务器上。在本地,这可以按照需要工作。
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 |
产生的错误:
operator does not exist: uuid = numeric
LINE 1: ..."tag_id" ) WHERE ("taggit_taggeditem"."object_id" = 21605304...
查找应该是uuid
针对另一个uuid
。不是numeric
。不明白它被转换的地点或原因。
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()
答案 0 :(得分:1)
您的模型的PK可能是UUID,但TaggedItem中GenericForeignKey字段的object_id
字段仍然是整数。
不幸的是,如果不修改taggit应用程序本身就不是一个很好的解决方法。