问题描述
我正在使用django 1.4.1并启用mysql和时区。我将数据转储到yaml,修改了一些字段以创建一些测试数据,并试图将其重新加载。但是,即使指定了tz,Django仍然抱怨朴素的日期时间
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
具体地说,我的loaddata有:
specifically, my loaddata has:
fields: {created_date: !!timestamp '2012-09-15 22:17:44+00:00', ...
,但是loaddata给出错误:
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:
- UTC时间戳
- 与Django使用dumpdata导出的格式完全相同
有什么办法可以告诉Django这是UTC日期吗?
is there some way i can tell django this is a UTC date?
推荐答案
从 ...
"2011-09-01T13:20:30+03:00"
天真日期时间,显然不是:
For a naive datetime, it obviously isn't:
"2011-09-01T13:20:30"
...因此而不是...
...so instead of...
created_date: !!timestamp '2012-09-15 22:17:44+00:00'
......
created_date: '2012-09-15T22:17:44+00:00'
...或...
created_date: '2012-09-15T22:17:44Z'
...将起作用。
这篇关于Loaddata无法正确处理时间戳和时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!