解决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 时间;

原文地址:https://www.cnblogs.com/xiao-apple36/p/10633459.html

时间: 2024-10-06 10:02:20

解决Database returned an invalid datetime value. Are time zone definitions for your database installed?的相关文章

Django(博客系统):按照时间分层筛选“/blog/article/?create_time__year=2017”,出现问题:Database returned an invalid datetime value. Are time zone definitions for your database installed?

问题背景 添加文章时间没问题,但为了设定博客文章按照时间分层筛选(创建时间的年份.年月&月份来搜索文章),我在blog这个django app的admin.py的ArticleAdmin类中做了如下设置: date_hierarchy = 'create_time' # 详细时间分层筛选 models.Article中create_time定义如下: create_time = models.DateTimeField(u'创建时间', auto_now_add=True) 设置后,后台呈现效果

Django Ubuntu:Database returned an invalid value in QuerySet.dates(). 错误的解决方法

运行Windows下创建的Django项目时,发生此错误! Database returned an invalid value in QuerySet.dates(). Are time zone definitions and pytz installed? 按提示先安装pytz 1.先安装easy_install: sudo apt-get install python-setuptools 2.进入官网,获取下载地址,使用wget命令下载: wget https://pypi.pytho

Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your datab

Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your database and pytz installed? 这样的问题一般出如今时差配置的问题上 首先错误信息提示是否定义你数据库的时区,是否安装pytz 网络上有说是由于mysql时区的问题,可是改动了貌似作用不大 最后发现是project中settings.py中的配置问题,修正 USE_TZ = Fals

报错Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your database and pytz installed?解决

在django中的setting.py中: LANGUAGE_CODE = 'en-us' TIME_ZONE = 'Asia/Shanghai' #'UTC' USE_I18N = True USE_L10N = True USE_TZ = True 由于USE_TZ=True开启了导致错误 解决方法: 在终端输入以下代码 mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql 输入mysql密码即可(注意上面语句中的m

Database returned an invalid value in QuerySet.datetimes()

安装pytz模块 修改setting.py,添加 import pytz from pytz import * 修改mysql timezone 执行如下命令:mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p  mysql 重启数据库

解决 django 博客归档 “Are time zone definitions for your database and pytz installed?”的错误

修改 project 中的settings 文件,问题解决! # USE_TZ = True USE_TZ = False # LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'zh-hans' # TIME_ZONE = 'UTC' TIME_ZONE = 'Asia/Shanghai'

解决;R语言使用sqldf库是报错"Failed to connect to database: Error: Access denied for user '..'@'localhost' (using password: NO) Error in !dbPreExists : invalid argument type"

原因:在使用sqldf时,不需要加载RMySQL库 解决方案:在控制台执行释放RMySQL库加载 detach("package:RMySQL", unload=T); 解决;R语言使用sqldf库是报错"Failed to connect to database: Error: Access denied for user '..'@'localhost' (using password: NO) Error in !dbPreExists : invalid argume

Execption:the database returned no natively generated identity value

org.hibernate.HibernateException: The database returned no natively generated identity value at org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity(IdentifierGeneratorHelper.java:90) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysD

mysql数据库中不能插入0000-00-00 00:00:00日期数据(报错Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00')

报错信息 SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'settlementTime' at row 1 我最后把mysql设置成可空,接受null型 参考:https://yq.aliyun.com/articles/17124 mysql数据库中不能插入0000-00-00 00:00:00日期数据(报错Invalid dat