Jay
Jay

Reputation: 799

columnMetadata.enum.map is not a function

When compiling my migration for my NestJs app it's breaking and I'm getting the following error with no effective way to trace it:

columnMetadata.enum.map is not a function

My linter shows no errors in any of my entities.

Upvotes: 0

Views: 1269

Answers (2)

Wilson Silva
Wilson Silva

Reputation: 1445

I want to also to add to your answer that the same error happens if you create an Enum of the same name as your entity and assign it to a column, example:

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;
}

The solution for that would be of course to rename your enum to a different name of add "Enum" at the end of the same.

Upvotes: 0

Jay
Jay

Reputation: 799

Found the issue:

@ApiProperty()
@Column({
  type: 'enum',
  enum: Type.Other,
})
type: Type;

I had defined the default as the enum in my entity class. Here's the corrected code:

@ApiProperty()
@Column({
  type: 'enum',
  enum: Type,
  default: Type.Other,
})
type: Type;

Upvotes: 1

Related Questions