Django 应用程序查询中的 Postgres 使用 PK UUID 字段 INT 而不是 UUID

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

为什么我的模型在此查找期间具有 UUID PK returns 其 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()

您的模型的 PK 可能是 UUID,但作为 TaggedItem 中 GenericForeignKey 字段的一部分的 object_id 字段仍然是一个整数。

不幸的是,如果不修改 taggit 应用程序本身,就没有真正解决这个问题的好方法。