【发布时间】:2019-12-25 21:11:00
【问题描述】:
我有一个使用 queryset.filter(date__gte=datetime(2011,1,1)) 准备的 Django 查询集
如果我随后调用str(queryset.query),我会在字符串中看到:
... WHERE "App_table"."date" >= 2011-1-1
但是,这是无效的 SQL 代码,就好像我在 Postgresql 中运行它一样,我收到此错误:
... WHERE "App_table"."date" >= 2011-1-1
ERROR: operator does not exist: date >= integer
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
为什么会发生这种情况?如何让 Django 输出我可以处理的正确 SQL 代码?
【问题讨论】:
标签: django postgresql django-orm