鉴于以下实体定义:
@Entity()
export class User extends BaseEntity {
@Column({ nullable: true })
name!: string | null;
@Column()
age!: number;
}
出现以下错误:typeORM: "message": "Data type \"Object\" in \"User.name" is not supported by \"postgres\" database."
...
name: 'DataTypeNotSupportedError',
message:
'Data type "Object" in "User.name" is not supported by "postgres" database.' }
在查看构建时,我看到 TS 发出的元数据将其作为对象进行寻址:__decorate([
typeorm_1.Column({ nullable: true }),
__metadata("design:type", Object)
], User.prototype, "name", void 0);
我究竟做错了什么?
最佳答案
问题源于这里的这一部分:
@Column({ nullable: true })
name!: string | null;
创建联合类型时,反射类型将为 Object
。克服它的一种简单方法是执行以下操作:
@Column({ nullable: true })
name?: string;
关于node.js - typeORM: "message": "Data type\"对象\"in\".. ."is not supported by\"postgres\"database.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64350794/