velog-server icon indicating copy to clipboard operation
velog-server copied to clipboard

typeorm index & unique

Open cjaewon opened this issue 4 years ago • 0 comments

// User.ts
  @Index()
  @Column({ unique: true, length: 255 })
  username!: string;

  @Index()
  @Column({ unique: true, length: 255, nullable: true, type: 'varchar' })
  email!: string | null;

SYNC가 true일 때 unique에는 index가 내장되어 있어서 @Index를 하면 duplicate key 오류가 나오는데

@Column 에서 unique를 빼주거나 @Index({ unique: true }) 또는 @Index를 제거해주고 @Column({ unique: true }) 로 해야 할 것 같습니다.

cjaewon avatar May 20 '20 03:05 cjaewon