django fixtures DateTimeField runtimeWarning django fixtures DateTimeField runtimeWarning django django

django fixtures DateTimeField runtimeWarning


Actually, the solution is hidden deeply in python docs, quote below:

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

"2011-09-01T13:20:30+03:00"

Such fixtures are fully accepted, in my case it was:

"2013-03-16T17:41:28+00:00""2013-03-17T23:36:12+00:00""2013-03-18T13:19:37+00:00"

and the output was:

$ ./manage.py loaddata articles/fixtures/initial_data.json Installed 3 object(s) from 1 fixture(s)

Note, that '2013-03-16 17:41:28 UTC+0000' is not proper timezone aware datetime format and it will give you following error:

DeserializationError: Problem installing fixture 'articles/fixtures/initial_data.json': [u"'2013-03-16 17:41:28 UTC+0000' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]


Also if you are using yaml to serialize there seems to be a bug in unserializing datetimes in PyYaml:

https://code.djangoproject.com/ticket/18867

Try either using json as serializer or you can add quotes around the datetime in the .yaml file.


You should probably look closer at your created_at field (you do know about auto_now_add=True?).

I'm guessing at what you're using, so you could try something like

import datetimefrom django.utils.timezone import utcArticle.created_at = datetime.datetime.utcnow().replace(tzinfo=utc)

Or you could disable the timezone support by setting

USE_TZ = False

in your settings.py

Or you could make your unaware datetime aware

import datetimeimport pytzutc=pytz.UTC#  where ever you get your datetime fromunaware = datetime.datetime(2013,3,16,17,41,28,0)now_aware = utc.localize(unaware)