案例类型整数和不带时区的时间无法匹配

2024-05-13 19:33:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码如下:

Songs.objects.filter(clients__id__in=client)\
    .annotate(
        logic_value=Case(
            When(after_n_values__isnull=False, then="aftervals_songs"),
            When(specific_time__isnull=False, then=F('specific_time')),
            distinct=True,
            output_field=models.TextField()))\
    .values('logic_value')

在这里,我得到一个错误,原因是:

When(specific_time__isnull=False, then=F('specific_time'))

因为specific_time在模型中是TimeField(),而after_n_values是一个整数。我实际上想检查(after_n_valuesspecific_time之间的值是否存在),然后它应该返回相应的值

但是,我得到了以下错误:

ProgrammingError: CASE types integer and time without time zone cannot be matched
LINE 1: ... WHEN "core_songs"."specific_time" IS NOT NULL THEN "core_songs"...

有谁能建议我如何使用when子句在这里检查日期是否如上所示是存在的还是空的


Tags: 代码corefalsetimevalue错误whenvalues