Why does Django call my datetimes naive when they are not?

I have a blog system that I create in Django 1.6, and I'm trying to make a YearArchiveView, or at least get a list of years with posts, from my PostTimeField model, pub_date. He continues to tell me that my pub_date is naive, but I explicitly changed them so that they are not.

Here are some touches I made in the python shell:

    >>> for post in posts:
...  post.pub_date
... 
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
datetime.datetime(2014, 1, 14, 3, 23, 2, tzinfo=<UTC>)
>>> years = Post.live.datetimes('pub_date', 'year', order='DESC')
/Users/.../django/db/models/fields/__init__.py:903: RuntimeWarning: DateTimeField Post.pub_date received a naive datetime (2014-01-13 21:40:01.051109) while time zone support is active.
  RuntimeWarning)

>>> years
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/.../django/db/models/query.py", line 71, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/Users/.../db/models/query.py", line 96, in __iter__
    self._fetch_all()
  File "/Users/.../django/db/models/query.py", line 854, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/Users/.../django/db/models/sql/compiler.py", line 1107, in results_iter
    raise ValueError("Database returned an invalid value "
ValueError: Database returned an invalid value in QuerySet.dates(). Are time zone definitions and pytz installed?
>>> import pytz
>>> posts[0].posted
datetime.datetime(2013, 9, 26, 0, 48, 8, tzinfo=<UTC>)
>>> 

What the hell is going on? I'm going crazy!

+4
source share
3 answers

I just finished creating a separate DateField on the model and then saved the DateTimeField date, so I don’t have to worry about a new set of .datetimes queries.

, , .

+1

, USE_TZ . . docs Django 1.6 queryset.dates

+1

Do you use SQLite as a database? It does not support time zones in datetimes .

+1
source

All Articles