typeorm: Adding an enum field does not generate a migration

Issue Description

When I add an enum item to an existing enum field on an Entity and run migration:generate, a blank migration is created

Expected Behavior

I expect a migration to be created to add add the field to the Postgres database

Actual Behavior

An empty migration is created

Steps to Reproduce

  1. Add an entity with an enum field:
export enum Status {
  Live = 'live',
  Draft = 'draft',
  Archived = 'archived',
}

@Entity({ name: 'something' })
export class Something {

  @Column({
    type: 'enum',
    enum: Status,
    default: Status.Draft,
  })
  status: OrganisationVersionStatus;
}
  1. Generate and run the migrations
  2. Add another enum field:
export enum Status {
  Live = 'live',
  Draft = 'draft',
  Archived = 'archived',
  Unconfirmed = 'unconfirmed',
}

@Entity({ name: 'something' })
export class Something {

  @Column({
    type: 'enum',
    enum: Status,
    default: Status.Draft,
  })
  status: OrganisationVersionStatus;
}
  1. Generate the migrations
  2. Result:
export class AddUnconfirmedStatusToSomething643119746947 implements MigrationInterface
{
  name = 'AddUnconfirmedStatusToSomething1643119746947';

  public async up(queryRunner: QueryRunner): Promise<void> {}

  public async down(queryRunner: QueryRunner): Promise<void> {}
}

My Environment

Dependency Version
Operating System Mac OS
Node.js version 16.13.0
Typescript version 4.4.4
TypeORM version 0.2.40

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

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, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

About this issue

Most upvoted comments

This happened to me because I was working with sync: true during my initial phase of development, and when I dropped the tables to generate the migrations, I forgot to drop the enums as well so they didn’t generate. This might be why adding _enum worked for @nikdale but there is most likely no need to. Hope this helps someone!

@Ginden I’m using NestJS, but I think this is the pertinent bit of my config:

{
    type: 'postgres',
    url: process.env.DATABASE_URL,
    entities: ['./dist/**/*.entity.js'],
    synchronize: false,
    migrations: ['./dist/db/migrate/*.js'],
    migrationsRun: true,
    dropSchema: process.env.NODE_ENV == 'test',
    cli: {
      migrationsDir: 'src/db/migrate',
    },
    extra: {
      ssl:
        process.env.NODE_ENV === 'production'
          ? { rejectUnauthorized: false }
          : false,
    },
  }