view raw
IMFletcher IMFletcher - 8 months ago 34
Python Question

Loaddata not dealing with timestamps and timezones properly

I'm using django 1.4.1 with mysql and timezones enabled. I did a dump data to yaml, modified some fields to create some test data, and am trying to load it back in. however, Django keeps complaining about naive datetimes even though a tz is specified

specifically, my loaddata has:

fields: {created_date: !!timestamp '2012-09-15 22:17:44+00:00', ...

but loaddata gives the error:

RuntimeWarning: DateTimeField received a naive datetime (2012-09-15 22:17:44) while time zone support is active.

This doesn't make much sense to me, seeing as its:

  1. a UTC timestamp

  2. the same exact format Django exported using dumpdata

is there some way i can tell django this is a UTC date?

Aya Aya

From the docs...

When serializing an aware datetime, the UTC offset is included, like this:


For a naive datetime, it obviously isn't:

"2011-09-01T13:20:30" instead of...

created_date: !!timestamp '2012-09-15 22:17:44+00:00'

...either of...

created_date: '2012-09-15T22:17:44+00:00'


created_date: '2012-09-15T22:17:44Z'

...will work.