django - Django 和 PosgresSQL 在每次保存时添加一个时区偏移量
问题描述
我的 django 和 postgresql 在每次保存时将时区偏移添加到日期时间字段。它在 sqlite 上正常工作。
>>> from picture.models import *
>>> p=Picture.objects.get(id=561)
>>> p.date_taken
datetime.datetime(2020, 8, 12, 19, 23, tzinfo=<UTC>)
>>> p.save()
>>> p=Picture.objects.get(id=561)
>>> p.date_taken
datetime.datetime(2020, 8, 12, 21, 23, tzinfo=<UTC>)
我在 django 设置中尝试了各种配置组合:
USE_TZ = True
TIME_ZONE = 'UTC'
postgresql.conf
timezone = 'Etc/UTC'
psql
ALTER ROLE albumusertest SET timezone TO 'UTC';
一些片段:来自 postgres
date_taken | timestamp with time zone | | not null |
django
date_taken = models.DateTimeField()
postgres 版本
psql (PostgreSQL) 11.12 (Debian 11.12-0+deb10u1)
django 3.2版
我真的很茫然。谁能帮我?
解决方案
推荐阅读
- mysql - Combining several similar queries
- python - 如何在 numpy 中累积用户定义的 ufunc?
- python - 如何在 Python 中替换单词。但是 "i" 到 "oraz" 和 "oraz" 到 "i"
- javascript - 使用 node.js 动态创建网页
- docker - 如何在 docker 中使用 heroku buildpacks
- reactjs - 在没有渲染方法的情况下访问 React Js 中的道具
- python - 将 Python 中的两个电子表格与 Pandas 合并,按“时间”列中最接近的“时间”,XX:XX:XX 格式的值
- mysql - 如果查询中的 COUNT-SELECT 不返回任何内容,则 MySQL 查询返回 false
- c# - 如何在 lambda 表达式和布尔类型之间进行转换
- javascript - 我只需要在用户完成输入后调用该函数