我认为Django创建了时区不可知的日期时间列,但是当我查看Postgres表时,我看到那里记录的值有时区信息。为什么Django使用时区创建Postgres时间戳列?
走得更远我发现Postgres后端指示Django创建使用时区的列。
从django的/分贝/后端/ PostgreSQL的/ creation.py:
data_types = {
...
'DateTimeField': 'timestamp with time zone',
...
架构表明创建的列被指定为 “时间戳与时区”。
CREATE TABLE notification_notice
(
...
created timestamp with time zone NOT NULL,
...
Postgres日志显示发送的更新语句。 Django根据我的Django设置文件的指示构建了一个使用UTC作为时区的SQL语句。
UPDATE "notification_notice" SET "sender_id" = 1, "group_id" = NULL, "notice_type_id" = 1, "content_type_id" = 21, "object_id" = 3, "created" = E'2011-11-11 22:31:08.022148' WHERE "notification_notice"."id" = 14
这就是我的表的样子。创建的列的时区具有“-08”时区。 Postgres必须检查我的系统时钟的时区以查找时区。
my_db=# select * from notification_notice limit 1;
id | sender_id | group_id | notice_type_id | content_type_id | object_id | created | last_interaction_time
----+-----------+----------+----------------+-----------------+-----------+------------------------------+-----------------------
1 | | 3 | 21 | 53 | 6 | 2011-11-11 14:31:02.98882-08 |
(1 row)
问题:
不Django的有放手政策时区?
为什么Postgres后端为models.DateTimeField使用时区?这是Postgres需要的吗?
有没有办法强制Django在Postgres中创建不使用时区的时间戳列?
可能的答案:[here](http://stackoverflow.com/questions/1869419/django-datetime-field-to-generate-timestamp-fields-without-timezone/1869568#1869568) – unutbu