当我运行以下查询时
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()"
我一直在与这个避风港挣扎,并且能够弄明白。任何帮助总是受到赞赏!
答案 0 :(得分:1)
django期待timestamp with time zone
但你通过了timestamp without time zone
。您必须将timezone
添加到您的时间或在USE_TZ = False
中设置settings.py
。
您可以使用pytz
添加timezone
。或者用这个:
timezone.now().replace(tzinfo=timezone.get_default_timezone())
用您的设置时区更改timezone
。