在为我的 NestJs 应用程序编译我的迁移时,它中断了,我收到以下错误,但没有有效的方法来跟踪它:
columnMetadata.enum.map is not a function
我的 linter 显示我的任何实体都没有错误。
发现问题:
@ApiProperty()
@Column({
type: 'enum',
enum: Type.Other,
})
type: Type;
我已经将
default
定义为我的实体类中的枚举。这是更正后的代码:
@ApiProperty()
@Column({
type: 'enum',
enum: Type,
default: Type.Other,
})
type: Type;
我还想在你的答案中补充一点,如果你创建一个与你的实体同名的枚举并将其分配给一个列,也会发生同样的错误,例如:
export class ExternalPartyType extends RestEntity {
@Column('varchar', { nullable: false, length: 100 })
public name: string;
@Column({
type: 'enum',
enum: ExternalPartyType,
nullable: false,
unique: true,
})
public type: ExternalPartyType;
}
解决方案当然是将枚举重命名为不同的名称,在末尾添加“Enum”。