Tuesday, December 1, 2015

Django celery task's timezone error

For some reason when I access the celery's tasks page in the Django's admin (.../djcelery/taskstate/), I got this error:

Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your database and pytz installed?

I have to do the following to get rid of the error:

1. Uncomment these settings:

# CELERY_TIMEZONE = 'UTC'
# CELERY_ENABLE_UTC = True

2. Add this under mysqld section in /etc/mysql/my.cnf:

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

3. Run the following command (without sudo):

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

4. Restart mysql:

$ sudo service mysql restart