SQLAlchemy server_default=text(“now()”) 无法正常工作

发布于 2025-01-16 04:55:39 字数 793 浏览 1 评论 0原文

我在数据库中有 utc 作为时区

,但在数据库中的某个地方(不知道在哪里)(+3:00)语言环境我在这个(+3:00)时间没有得到 utc bat。

知道为什么吗?以及如何修复?

这就是表 orm 描述的样子

class AccountingQueueInvoice(Base):  # created on invoice final approve by operator
    __tablename__ = 'accounting_queue_invoice'

    invoice_id = Column(ForeignKey('invoices.id', ondelete='CASCADE'), primary_key=True)
    validated_at = Column(DateTime, server_default=text("now()"))

这就是我创建记录的方式

def create_accounting_queue_invoice(invoice_id, session):
    ref = session.query(AccountingQueueInvoice).where(AccountingQueueInvoice.invoice_id == invoice_id).one_or_none()
    if ref is None:
        info = AccountingQueueInvoice(
            invoice_id=invoice_id,
        )
        session.add(info)

I have utc in db as timezone

but somewhere (no idea where) (+3:00) locale in in db I get not utc bat this (+3:00) time.

Any idea why? and how to fix ?

This is how table orm description looks like

class AccountingQueueInvoice(Base):  # created on invoice final approve by operator
    __tablename__ = 'accounting_queue_invoice'

    invoice_id = Column(ForeignKey('invoices.id', ondelete='CASCADE'), primary_key=True)
    validated_at = Column(DateTime, server_default=text("now()"))

This is how i create a record

def create_accounting_queue_invoice(invoice_id, session):
    ref = session.query(AccountingQueueInvoice).where(AccountingQueueInvoice.invoice_id == invoice_id).one_or_none()
    if ref is None:
        info = AccountingQueueInvoice(
            invoice_id=invoice_id,
        )
        session.add(info)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就是爱搞怪 2025-01-23 04:55:39

问题出

-bash-4.2$ cat postgresql.conf | grep timez
timezone = 'W-SU'

在数据库

show timezone;

返回中

UTC

problem was with

-bash-4.2$ cat postgresql.conf | grep timez
timezone = 'W-SU'

but in db

show timezone;

returns

UTC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文