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
相关产品推荐
相关产品推荐

