问题描述
在我将一些 Wordpress 内容导入 Mezzanine 的 blog_blogpost 后,我在装有 mysql 5.5 的 Ubuntu 12.04 机器上收到此错误.
I get this error on my Ubuntu 12.04 machine with mysql 5.5 after I imported some Wordpress content to Mezzanine's blog_blogpost.
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
I added to my local_settings.py
import pytz
from pytz import *
并且还在 my.cnf [mysqld] 中定义了时区
and also defined timezone in my.cnf [mysqld]
default-time-zone = "+01:00"
但我仍然得到错误单元我在模板中得到了这一行:
but I still get the error unitl I get the line in template:
标签是:
140 {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
140 {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
感谢您帮助解决问题.
推荐答案
看起来是错误引起的 Django 1.6 时区功能变化.文档现在特别提到了这个错误(错误报告,链接到文档).
Looks like error caused Django's 1.6 timezone functionality changes. The docs now mention this error specifically (bug report, link to docs).
您必须将时区表加载到 mysql (http://dev.mysql.com/doc/refman/5.6/en/mysql-tzinfo-to-sql.html).尝试在您的数据库服务器上执行:
You have to load timezone tables into mysql (http://dev.mysql.com/doc/refman/5.6/en/mysql-tzinfo-to-sql.html). Try execute on your database server:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -D mysql -u root -p
然后运行刷新表"或刷新查询缓存",否则即使加载了正确的时区数据,问题也可能不会消失:
And then run "flush tables" or "flush query cache", otherwise the problem may not disappear even though you've loaded the correct timezone data:
mysql -u root -p -e "flush tables;" mysql
由@qris 更新
这篇关于数据库在 QuerySet.dates() 中返回了无效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!