首页 > 解决方案 > 我还能如何在 postgresql/django python shell 中编写带有时区的时间戳?

问题描述

我正在使用 postgres db 开发 django API 项目。我还添加了一个 serializers.py 文件。我正在尝试通过 python shell 在数据库中添加一行来测试我所做的事情,但我不断收到此错误:

django.db.utils.ProgrammingError: column "date_created" is of type timestamp with time zone but expression is of type time without time zone
LINE 1: ...bility" = NULL, "rating" = NULL, "date_created" = '00:00:00'...
                                                            ^
HINT:  You will need to rewrite or cast the expression.

这是代码:

from vendor.models import Vendors
from vendor.serializers import VendorsRegisterSerializer
p  = Vendors(id=1, first_name='Flavio', last_name='Akin', email='sheeku@gmail.com', profession='plumber', username='Flanne', pin='1234', phone_number='12345678901', number_of_jobs=300, number_of_patrons=788, date_created='21:00:00 +05:00')

我尝试将date_createdvalue'21:00:00 +05:00'替换为'21:00:00 EST''21:00+05''21:00:00+05'我不断收到相同的错误。

任何帮助将不胜感激。提前致谢。

标签: djangopostgresqltimestamp

解决方案


推荐阅读