Node.js 具有CRUD装饰器列的NestJS不存在

Node.js 具有CRUD装饰器列的NestJS不存在,node.js,nestjs,typeorm,Node.js,Nestjs,Typeorm,我有一个RESTAPI服务器,使用NestJS和typeorm,控制器上有CRUD装饰器。 我有一个用户实体 userEntity { @PrimaryGeneratedColumn() id: number @PrimaryColumn({ unique: true }) username: string @Column({ nullable: true }) email: string @Column({ nullable: true }) phone:

我有一个RESTAPI服务器,使用NestJS和typeorm,控制器上有CRUD装饰器。 我有一个用户实体

userEntity {
@PrimaryGeneratedColumn()
  id: number

  @PrimaryColumn({ unique: true })
  username: string


  @Column({ nullable: true })
  email: string

  @Column({ nullable: true })
  phone: string

  @PrimaryColumn()
  role: string
}
  • 我知道用户名也是主列(我有更多列),但我需要通过用户名和角色(或id)来识别用户
我还有另一个实体(家庭信息)

但我得到一个错误“column FamilyFoEntity.parent\u用户名不存在” 当我尝试获取所有家庭信息时(localhost:3000/api/family info)

我的数据库为空,用户表上没有行,家庭信息表上没有行。。。 我认为这不是问题所在


谢谢。

您需要用
@Entity()
注释标记每个类

@Entity()
class FamilyInfoEntity {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ nullable: true })
  familyName: string

  @Column({ nullable: true })
  parentId?: number

  @OneToOne(() => UserEntity, parent => parent.id, { nullable: true })
  @JoinColumn()
  parent?: UserEntity
} ```
@Entity()
class FamilyInfoEntity {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ nullable: true })
  familyName: string

  @Column({ nullable: true })
  parentId?: number

  @OneToOne(() => UserEntity, parent => parent.id, { nullable: true })
  @JoinColumn()
  parent?: UserEntity
} ```