node.js - typeORM: "message": "Data type\"对象\"in\".. ."is not supported by\"postgres\"database."

标签 node.js typescript postgresql typeorm reflect-metadata

鉴于以下实体定义:

@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/

相关文章:

Mysql 返回不正确的 bigint 结果 1,非常奇怪的错误

node.js - mongoDB同时更新2个集合

node.js - 使用 typescript 2 使用 sequelize 模型扩展 express 请求对象

python - 如何在与 SQLAlchemy 和 psycopg2 的 PostgreSQL 连接上设置 `lock_timeout`?

sql - 基于不同列的列重叠

node.js - Elasticsearch - 基于文本长度的查询

javascript - 无限循环而不是移动到下一个文件夹

javascript - 在 typescript 中映射类

javascript - Angular 无法将用户输入从 html 传递给 typescript

sql - 查询日期范围postgresql