【发布时间】:2022-07-22 19:31:28
【问题描述】:
我的项目(带有 TypeScript 的 NestJS)在 PostgreSQL 数据库上使用 TypeOrm。
我的表有一个列(在迁移文件中):
new TableColumn({
name: 'managed_at',
type: 'timestamp',
isNullable: true,
}),
实体类中的关联字段:
@Column({ type: 'timestamp', nullable: true })
managedAt: Date | null;
我希望 managed_at 列保存日期和时间的值。
如果我将数据保存到表中:
import { Repository } from 'typeorm';
...
// repo is the Repository of typeorm
repo.update(
{ managedAt: Date.now() }
);
我得到错误:
QueryFailedError: date/time field value out of range: "1651495656811"
如何解决使用 Date.now() 保存数据和时间值的问题?
【问题讨论】:
标签: postgresql typeorm node.js-typeorm