数据库在QuerySet.dates()中返回无效值 [英] Database returned an invalid value in QuerySet.dates()

查看:154
本文介绍了数据库在QuerySet.dates()中返回无效值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ValueError在我的Ubuntu 12.04机器上,当我将一些WordPress内容导入到Mezzanine的blog_blogpost之后,我的Ubuntu 12.04机器出现了这个错误。 at / admin / blog / blogpost / 
数据库在QuerySet.dates()中返回无效值。是否安装了时区定义和pytz?

请求方法:GET
请求URL:http://127.0.0.1:8000/admin/blog/blogpost/
Django版本:1.6.1
异常类型:ValueError
异常值:
数据库在QuerySet.dates()中返回无效值。是否安装了时区定义和pytz?
异常位置:/home/me/.mezenv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py在results_iter,行1107
Python可执行文件: /home/me/.mezenv/bin/python
Python版本:2.7.3
Python路径:
[u'/ home / me',
'/ home / me / sai',
'/home/me/.mezenv/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/ home /我/ .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']
服务器时间:星期六,2014年1月25日13:44:11 +0100


模板渲染时出错

在模板/home/me/.mezenv/local/lib/python2.7/site-packages/grappelli_safe/templates/admin/change_list.html中,第140行错误

我添加到我的local_settings.py

  import pytz 
from pytz import *

并在我的时间段中定义了时区。 cnf [mysqld]

  default-time-zone =+01:00

但我仍然得到错误unitl我得到了模板中的行:



标签是:


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


欣赏你的帮助来解决它。

解决方案

看起来像错误导致 Django的1.6时区功能更改。该文档现在特别提及此错误(错误报告链接到docs



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

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

然后运行flush tables或flush query cache ,否则问题可能不会消失,即使您已经加载了正确的时区数据:

  mysql -u root -p  - e冲水表; mysql 

由@qris更新


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

I added to my local_settings.py

import pytz
from pytz import *

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:

the tag is:

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

Appreciate your help to resolve it.

解决方案

Looks like error caused Django's 1.6 timezone functionality changes. The docs now mention this error specifically (bug report, link to docs).

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 

updated by @qris

这篇关于数据库在QuerySet.dates()中返回无效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆