Mezzanine运行了一段时间,添加一个Blog的时候出来如下错误:
Database returned an invalid value in QuerySet.dates(). Are time zone definitions and pytz installed?
这个错误和Django的时区处理有关系。
1 安装pytz
按照提示,最直接的解决方法应该是安装:
pip freeze | grep pytz #检查一下,发现系统其实装过了
2 设置mysql的时区
可能是mysql的时区问题,设置时区常用的是如下两种方法:
推荐使用第二种”修改数据库的信息”,因为对mysql的配置文件进行修改容易让mysql当机。
第一种 修改mysql的配置
in the file “my.cnf” in the [mysqld] section
default_time_zone='+08:00'
第二种 修改数据库的信息
登录mysql as root.
select @@global.time_zone;
select now();
SET GLOBAL time_zone = '+8:00';
问题照旧。
3 mysql加载time zone
继续查django的文档:
The mysql_tzinfo_to_sql program loads the time zone tables in the mysql database. It is used on systems that have a zoneinfo database (the set of files describing time zones).
于是这样执行:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -pyourpassword mysql
After running mysql_tzinfo_to_sql, it is best to restart the server so that it does not continue to use any previously cached time zone data. 那就重启了下mysql, 终于正常了。