代码之家  ›  专栏  ›  技术社区  ›  ffxsam

无法使用TypeORM设置Postgres中uuid或enum字段的值

  •  0
  • ffxsam  · 技术社区  · 4 年前

    我已经在这上面呆了一个小时了,不幸的是在文件里找不到任何相关的东西。

    我无法在使用以下类型的字段上设置值 enum uuid . 例如:

    export enum PhotoStatus {
      WORKING = 'WORKING',
      DONE = 'DONE'
    }
    
    export class Photo {
      @PrimaryGeneratedColumn()
      id: number:
      
      @Column()
      size: string;
    
      @Column({
        type: 'enum',
        enum: PhotoStatus,
        default: PhotoStatus.WORKING,
      })
      status: PhotoStatus;
    }
    

    但当我试图创造一个新的记录时,就像这样:

      const photo = new Photo();
      photo.size = 'huge';
      photo.status = PhotoStatus.DONE;
      await connection.manager.save(photo);
    

    它抛出一个错误:

    BadRequestException: ERROR: column "status" is of type content_status_enum but expression is of type character varying
      Hint: You will need to rewrite or cast the expression.
    

    uuid列也会发生这种情况。

    0 回复  |  直到 4 年前