一尘不染

数据库在QuerySet.dates()中返回了无效值

django

在将一些Wordpress内容导入夹层的blog_blogpost之后,在具有mysql 5.5的Ubuntu 12.04计算机上收到此错误。

ValueError at /admin/blog/blogpost/
Database returned an invalid value in QuerySet.dates(). Are time zone definitions and pytz installed?

Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/blog/blogpost/
Django Version: 1.6.1
Exception Type: ValueError
Exception Value:    
Database returned an invalid value in QuerySet.dates(). Are time zone definitions and pytz installed?
Exception Location: /home/me/.mezenv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py in results_iter, line 1107
Python Executable:  /home/me/.mezenv/bin/python
Python Version: 2.7.3
Python Path:    
[u'/home/me',
 '/home/me/sai',
 '/home/me/.mezenv/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
 '/home/me/.mezenv/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
 '/home/me/.mezenv/lib/python2.7',
 '/home/me/.mezenv/lib/python2.7/plat-linux2',
 '/home/me/.mezenv/lib/python2.7/lib-tk',
 '/home/me/.mezenv/lib/python2.7/lib-old',
 '/home/me/.mezenv/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/home/me/.mezenv/local/lib/python2.7/site-packages']
Server time:    Sat, 25 Jan 2014 13:44:11 +0100


Error during template rendering

In template /home/me/.mezenv/local/lib/python2.7/site-packages/grappelli_safe/templates/admin/change_list.html, error at line 140

我添加到了local_settings.py

import pytz
from pytz import *

并在my.cnf [mysqld]中定义了时区

default-time-zone = "+01:00"

但是我仍然得到错误unitl我在模板中得到了这一行:

标签是:

140 {%block date_hierarchy%} {%date_hierarchy cl%} {%endblock%}

感谢你的帮助以解决该问题。


阅读 352

收藏
2020-03-31

共1个答案

一尘不染

看起来是由于Django 1.6时区功能更改引起的错误。现在,文档特别提到了此错误(错误报告,指向文档的链接)。

你必须将时区表加载到mysql中(http://dev.mysql.com/doc/refman/5.6/en/mysql-tzinfo-to-sql.html)。尝试在数据库服务器上执行:

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -D mysql -u root -p 

然后运行“刷新表”或“刷新查询缓存”,否则即使你已加载正确的时区数据,问题也可能不会消失:

mysql -u root -p -e "flush tables;" mysql 
2020-03-31