【问题标题】:Django 1.10 full text search by UUIDField returns DataError通过 UUIDField 进行的 Django 1.10 全文搜索返回 DataError
【发布时间】:2017-01-23 05:17:45
【问题描述】:

我有以下型号:

class Show(models.Model):
    cid = models.UUIDField(
        default=uuid.uuid4,
        editable=False,
        verbose_name="Content ID",
        help_text="Unique Identifier"
    )
    title_short = models.CharField(
        max_length=60,
        blank=True,
        verbose_name="Short Title",
        help_text="Short title (60 chars)"
    )

我正在使用下面的sn-p

from django.contrib.postgres.search import SearchVector
Entry.objects.annotate(
    search=SearchVector('cid'),
).filter(search='wateva')

返回:

DataError at /meta/shows/

invalid input syntax for uuid: ""
LINE 1: ...unt", to_tsvector(COALESCE("entities_show"."cid", '')) AS    "s...

我尝试使用 PostgreSQL 9.3.14 和 PostgreSQL 9.5.3、Python 3.4.3

有人遇到过这个问题吗?

【问题讨论】:

    标签: python django postgresql full-text-search uuid


    【解决方案1】:

    您可能需要提交错误报告。

    Django 代码创建一个 COALESCE() 语句,假设空字符串 ('') 的最终回退值对于给定的字段是可接受的。 我没有看到通过官方 API 指定回退值的方法,并且由于 UUID 字段被转换为 Postgres Native UUID 字段,因此空字符串是该字段的无效值。

    如果您决定提交报告,请在此处添加带有工单 ID 的评论,我可能会修复它,因为我对此功能有既得利益。

    【讨论】:

      猜你喜欢
      • 2017-09-21
      • 1970-01-01
      • 2017-12-09
      • 2017-03-31
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      相关资源
      最近更新 更多