typeorm: Column of type "enum" throws missing properties error

Hello there!

Issue Description

The version of TypeORM was updated to the latest release, while starting up the NestJS server it started throwing this enum error. As of my understanding the required properties are in the decorator.

Expected Behavior

To start correctly the TypeOrmCoreModule

Actual Behavior

Error: Column "type" of Entity "StandardSet" is defined as enum, but missing "enum" or "enumName" properties.

Steps to Reproduce

This code worked in version 0.2.31, once it was upgraded to 0.2.32 this error started appearing.

enum StandardSetType {
  AcademicStandard = 'AcademicStandard',
  FoundationalKnowledge = 'FoundationalKnowledge',
  AchievementDescriptor = 'AchievementDescriptor',
}

@Column('enum', { enum: StandardSetType, name: 'type' })
type: StandardSetType;

My Environment

Dependency Version
Operating System Ubuntu
Node.js version v14.15.5
Typescript version 3.9.9
TypeORM version 0.2.32
NestJS 7.6.13
nestJS/TypeORM 7.1.5

Additional Context

Relevant Database Driver(s)

  • aurora-data-api
  • aurora-data-api-pg
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time, and I know how to start.
  • Yes, I have the time, but I don’t know how to start. I would need guidance.
  • No, I don’t have the time, although I believe I could do it if I had the time…
  • No, I don’t have the time and I wouldn’t even know how to start.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 10
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I faced the problem and mine was all about circular dependency and load order. I had two files of my entities:

// EntityA.ts
import { EntityB } from './EntityB' 

export enum SomeEnum {
  ONE = 'one',
  TWO = 'two',
}

export class EntityA {
  @ManyToOne(() => EntityB)
  @JoinColumn()
  entityB: EntityB;
}
// EntityB.ts
import { SomeEnum } from './EntityA' 

console.log(SomeEnum); // PROBLEM! SomeEnum is undefined 
export class EntityB {
  @Column({ type: 'enum', enum: SomeEnum })
  enumColumn: SomeEnum;
}

One of the solutions to move your enum into separate file. Maybe this will help someone

I could reproduce this issue, when the same enum was used by 2 different entities

Cannot replicate.

When opening an issue, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This boils down to ensuring your code that reproduces the problem follows the following guidelines:

  • Minimal – Use as little code as possible that still produces the same problem
  • Complete – Provide all parts someone else needs to reproduce your problem in the question itself
  • Reproducible – Test the code you’re about to provide to make sure it reproduces the problem

Minimal

The more code there is to go through, the less likely people can find your problem. Streamline your example in one of two ways:

  1. Restart from scratch. Create a new program, adding in only what is needed to see the problem. Use simple, descriptive names for functions and variables – don’t copy the names you’re using in your existing code.
  2. Divide and conquer. If you’re not sure what the source of the problem is, start removing code a bit at a time until the problem disappears – then add the last part back.

Don’t sacrifice clarity for brevity when creating a minimal example. Use consistent naming and indentation, and include code comments if needed. Use your code editor’s shortcut for formatting code.

Don’t include any passwords or credentials that must be kept secret.

Complete

Make sure all information necessary to reproduce the problem is included in the issue itself.

If the problem requires some code as well as some XML-based configuration, include code for both. The problem might not be in the code that you think it is in.

Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block.

DO NOT use images of code. Copy the actual text from your code editor, paste it into the issus, then format it as code. This helps others more easily read and test your code.

Reproducible

To help you solve your problem, others will need to verify that it exists.

Describe the problem. “It doesn’t work” isn’t descriptive enough to help people understand your problem. Instead, tell other readers what the expected behavior should be. Tell other readers what the exact wording of the error message is, and which line of code is producing it. Use a brief but descriptive summary of your problem as the title of your question.

Eliminate any issues that aren’t relevant to the problem. If your question isn’t about a compiler error, ensure that there are no compile-time errors.

Double-check that your example reproduces the problem! If you inadvertently fixed the problem while composing the example but didn’t test it again, you’d want to know that before asking someone else to help.

After switching typeorm version from 0.2.31 -> 0.2.45. i had case of getting error (but in large codebase): TypeORMError: Column "x" of Entity "y" is defined as enum, but missing "enum" or "enumName" properties..

In one of the comments it was mentioned that issue is in enum defined in one entity file, but used in some other entities (in other entity files). After extracting that enum in separate file, and adding enum attribute inside @Column decorator, migrations were successfully executed.

The only thing that fixed the issue for me was to extract the enum into a separate file.

I happen to use the { type: 'enum', enum: StandardSetType } syntax. Does that work for you?

The problem still persist on version 0.2.31.

If you try use an Enum from other Entity, he will throw the error

I happen to use the { type: 'enum', enum: StandardSetType } syntax. Does that work for you?

It worked for me, thanks!