Database returned an invalid value in QuerySet.dat

2019-01-12 21:23发布

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.

7条回答
干净又极端
2楼-- · 2019-01-12 22:02

The Django docs actually talk about this problem:

I get an error “Are time zone definitions for your database and pytz installed?” pytz is installed, so I guess the problem is my database?

If you are using MySQL, see the Time zone definitions section of the MySQL notes for instructions on loading time zone definitions.

If you follow that link, you get this advice:

If you plan on using Django’s timezone support, use mysql_tzinfo_to_sql to load time zone tables into the MySQL database. This needs to be done just once for your MySQL server, not per database.

Here's the command:

mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql mysql
查看更多
登录 后发表回答