You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TypeORM报错:AnnouncementWidget#workspace列类型未定义且无法推断

解决TypeORM错误:Column type for AnnouncementWidget#workspace is not defined and cannot be guessed

错误的根源是你给workspace字段同时使用了@Column和@PrimaryColumn装饰器。在TypeORM中,@PrimaryColumn本身就负责定义主键列的属性,不需要额外叠加@Column,两者混用会导致框架无法正确解析列的类型配置,从而抛出这个错误。

直接把@Column装饰器移除,将原@Column中的配置参数移到@PrimaryColumn里即可,因为@PrimaryColumn支持接收和@Column完全一致的配置项:

@Entity()
export class AnnouncementWidget {
  @Index()
  @PrimaryColumn({
    type: "text",
    nullable: false,
    unique: true,
    comment: "Workspace (company/subdomain) that these settings belongs to",
  })
  workspace!: string;

  @Column({
    type: "text",
    nullable: false,
    comment: "The announcement's title",
  })
  title!: string;

  @Column({
    type: "jsonb",
    nullable: false,
    comment:
      "The announcement's message. Stored as JSON because it includes rich text content.",
  })
  message!: object;
}

这样修改后,TypeORM就能正确识别workspace列的类型和属性,错误会被解决。

内容的提问来源于stack exchange,提问作者callmetwan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 00:46:09