TypeOrm:即使数据存在,PrimaryGeneratedColumn() 从 1 开始

时间:2021-01-04 04:59:28

标签: typeorm

我正在使用 Typeorm + typegraphql + Postgre。

我有一个 Contact 表,定义为:


@Entity("contact")
@ObjectType()
export class Contact extends BaseEntity {
  @Field((type) => Number)
  @PrimaryGeneratedColumn()
  readonly id!: number;

  @Field()
  @Column({ length: 128, unique: true })
  name!: string;
}

如果db为空,生成的id从1开始,用graphql添加新联系人效果很好。

但是如果我用pgAdmin导入一些数据,然后添加新的联系人,postgre报错duplicate key value violates unique constraint "PK_xxx",id还是从1生成的,导致报错。

有什么办法可以让这个工作吗?

0 个答案:

没有答案