velog-server
velog-server copied to clipboard
typeorm index & unique
// 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 })
로 해야 할 것 같습니다.