mezzanine timezone 的问题

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, 终于正常了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值