programing

데이터베이스가 QuerySet.dates ()에서 잘못된 값을 반환했습니다.

minecode 2021. 1. 17. 10:47
반응형

데이터베이스가 QuerySet.dates ()에서 잘못된 값을 반환했습니다.


일부 Wordpress 콘텐츠를 Mezzanine의 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"

하지만 여전히 오류가 발생합니다. 템플릿에 줄이 표시됩니다.

태그는 다음과 같습니다.

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

문제를 해결하는 데 도움을 주셔서 감사합니다.


오류로 인해 Django의 1.6 시간대 기능이 변경된 것 같습니다 . 문서는 이제이 오류를 구체적으로 언급합니다 ( bug report , link to docs ).

시간대 테이블을 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 

그런 다음 "flush tables"또는 "flush query cache"를 실행합니다. 그렇지 않으면 올바른 시간대 데이터를로드 한 경우에도 문제가 사라지지 않을 수 있습니다.

mysql -u root -p -e "flush tables;" mysql 

@qris에 의해 업데이트 됨


MacOS 사용자의 경우 여기 에서 해결책을 찾았 습니다 (댓글).

mysql_tzinfo_to_sql /usr/share/zoneinfo | sed -e "s/Local time zone must be set--see zic manual page/local/" | mysql -u root mysql

MacOS에서는 다음과 같은 오류가 있습니다.

$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u roomysql

Warning: Unable to load '/usr/share/zoneinfo/+VERSION' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh87' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh88' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh89' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh87' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh88' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh89' as time zone. Skipping it.
ERROR 1406 (22001) at line 38981: Data too long for column 'Abbreviation' at row 1

나를 위해 일한 것 :

1. 'mysql'테이블에 시간대 정의를 입력합니다.

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

2. 플러시 테이블

mysql -u root -p -e "flush tables;" mysql 

3. mysql 다시 시작

sudo service mysql restart

Mavericks에서 같은 문제로 여기를 지나가는 다른 사람에게는 Anton이 언급 한 오류가 발생했습니다.

ERROR 1406 (22001) at line 38981: Data too long for column 'Abbreviation' at row 1

그래서 사용 mysql_tzinfo_to_sql tz_file tz_name으로부터 MySQL의 문서 내가 원하는 것을 특정 시간대를로드;

mysql_tzinfo_to_sql /usr/share/zoneinfo/GMT GMT | mysql -u root -p mysql
mysql_tzinfo_to_sql /usr/share/zoneinfo/UTC UTC | mysql -u root -p mysql

그리고 이제 Django는 오류를 반환하지 않으므로 행복합니다 : D


Windows의 경우 다음 단계를 수행하십시오.

  • 서비스 중지
  • download the files provided by MySQL but note they go in
    C:\ProgramData\MySQL\MySQL Server VERSION\data\mysql
    not in
    C:\Program Files\MySQL\MySQL Server VERSION\data
    at least on Windows 7 as of 2014.
  • I also modified C:\Program Files\MySQL\MySQL Server VERSION\my.ini to add default-time-zone = 'UTC' per the tips here. Then restart the service.

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

Loading Time Zone for Mysql solved the problem for me. If you are on windows, follow these instructions :

Step #1: Download the package that contains the data files of pre-built time zone tables. http://dev.mysql.com/downloads/timezones.html

Step #2: Unzip the downloaded ZIP file to a folder on your Desktop.

Step #3: Stop MySQL Server.

For Xampp and Wamp use their GUI or stop the mysql service from the Task Manager.

Step #4: Open mysql subdirectory of your MySQL server's data directory.

For me it is C:\xampp\mysql\data\mysql

Step #5: Overwrite time zone data files with the downloaded version.

Copy all 15 data files from your unzipped folder and paste into data folder for the mysql system database. Overwrite all these .frm, .MYD, and .MYI files.

Step #6: Restart MySQL server.

And the job is done :-)

source : http://www.geeksengine.com/article/populate-time-zone-data-for-mysql.html

ReferenceURL : https://stackoverflow.com/questions/21351251/database-returned-an-invalid-value-in-queryset-dates

반응형