在 python 中运行我的 sql 时出现以下错误
/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py:64: RuntimeWarning: SQLite received a naive datetime (2012-06-22 15:53:43) while time zone support is active.
我的查询也返回了错误的数据。如果我将时间更改为 2 小时(17:53:43 而不是 15:53:43),我的时区 atm 是 gmt +2 所以我认为问题出在时区。
如何更改我的查询以使 sql 以我想要的方式执行?
sql:
sqlQuery = """SELECT w.id, w.serial, w.finishdate, w.weighingtype_id, w.netto, w.bruto, w.deleted
FROM weighing w
LEFT JOIN weighing w1
ON w1.id = w.parent_id
WHERE w.user_id = %(userid)s"""
if date:
sqlQuery = sqlQuery + " AND (w.created = %(date)s OR w.modified > %(date)s)"
编辑:添加了我用于转换日期时间的代码
data = request.GET.copy()
if 'date' in data:
try:
data['date'] = datetime.datetime.strptime(data['date'], "%Y-%m-%dT%H:%M:%S")
except:
raise error(311)