Loaddata 未正确处理时间戳和时区

Loaddata not dealing with timestamps and timezones properly(Loaddata 未正确处理时间戳和时区)
本文介绍了Loaddata 未正确处理时间戳和时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用启用了 mysql 和时区的 django 1.4.1.我将数据转储到 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:

  1. UTC 时间戳
  2. 与 Django 使用 dumpdata 导出的完全相同的格式

有什么方法可以告诉 django 这是一个 UTC 日期吗?

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

推荐答案

来自 docs...

在序列化感知日期时间时,包括 UTC 偏移量,例如这个:

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

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

对于一个天真的日期时间,显然不是:

For a naive datetime, it obviously isn't:

"2011-09-01T13:20:30"

...所以不是...

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 未正确处理时间戳和时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)