解决Database returned an invalid datetime value. Are time zone definitions for your database installed
Posted xiao-apple36
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决Database returned an invalid datetime value. Are time zone definitions for your database installed相关的知识,希望对你有一定的参考价值。
设定博客文章按照时间分层筛选出现问题
ret=Article.objects.filter(user=user).annotate(month=TruncMonth("create_time")).values("month").annotate(c=Count("nid")).values_list("month","c") print("ret----->",ret)
解决方案:
修改settings.py中时区配置信息:
# LANGUAGE_CODE = ‘en-us‘ # # TIME_ZONE = ‘Asia/Shanghai‘ # # USE_I18N = True # # USE_L10N = True # # USE_TZ = True # 解决Database returned an invalid datetime value. Are time zone definitions for your database installed? LANGUAGE_CODE = ‘zh-hans‘ TIME_ZONE = ‘Asia/Shanghai‘ USE_I18N = True USE_L10N = True
注意问题:
启用 USE_TZ = True 后,处理时间方面,有两条 “黄金法则”:
保证存储到数据库中的是 UTC 时间;
在函数之间传递时间参数时,确保时间已经转换成 UTC 时间;
以上是关于解决Database returned an invalid datetime value. Are time zone definitions for your database installed的主要内容,如果未能解决你的问题,请参考以下文章
There is already an object named ‘#xxxx‘ in the database.
(笔记)VC6插件安装--Unable to register this add-in because its DllRegisterServer returns an error
Django(博客系统):按照时间分层筛选“/blog/article/?create_time__year=2017”,出现问题:Database returned an invalid datet
spark Failed to get database default, returning NoSuchObjectException
VC6插件安装--Unable to register this add-in because its DllRegisterServer returns an error (转)
703. Kth Largest Element in a Stream/215. Kth Largest Element in an Array/