3

当我运行以下查询时

Viewed.objects.raw('SELECT "recently_viewed_viewed"."id"FROM "recently_viewed_viewed" WHERE NOT ("recently_viewed_viewed"."viewed_date" <= \'timezone.now()\' AND "recently_viewed_viewed"."user_id" = user_id)' )

我明白了

DataError: invalid input syntax for type timestamp with time zone: "timezone.now()"

我一直在努力解决这个问题,无法弄清楚。任何帮助都将受到赞赏!

4

1 回答 1

1

django expecttimestamp with time zone但是你通过了timestamp without time zone。您必须添加timezone到您的时间或设置USE_TZ = False在您的settings.py.

您可以pytz用于添加timezone。或使用这个:

timezone.now().replace(tzinfo=timezone.get_default_timezone())

用于更改timezone您的设置时区。

于 2014-10-30T22:14:49.917 回答