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
- 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;
}
- Generate and run the migrations
- 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;
}
- Generate the migrations
- 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
- Original URL
- State: open
- Created 2 years ago
- Comments: 15
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: