#11480·typeorm

Bug with typeorm and Migration and entity decorator

Author: SNEAXIIICreated May 15, 2025Updated Sep 23, 2026

Issue description

Hello, when I generate a migration with typeorm when I use a name for my entity decorator, the migration have a strange behavior

Expected Behavior

Given I want to generate a migration for my entities When I generate and I run it on my database Then The database is successfully synchronized When I modify one entity on my code and I generate another migration Then The new migration contains only the new modification

Actual Behavior

Given I want to generate a migration for my entities When I generate and I run it on my database Then The database is successfully synchronized When I modify one entity on my code and I generate another migration Then The new migration contains every entity present in the previous migration + the addition

Steps to reproduce

Sample of typeorm config

typescript
import { registerAs } from '@nestjs/config';
import { config as dotenvConfig } from 'dotenv';
import { Category } from '../models/category.model';

dotenvConfig({ path: '.env' });

const config = {
  type: 'mariadb',
  host: ${process.env.MARIADB_HOST},
  port: ${process.env.MARIADB_PORT},
  username: ${process.env.MARIADB_USER},
  password: ${process.env.MARIADB_PASSWORD},
  database: ${process.env.MARIADB_DATABASE},
  entities: [Category],
  migrations: ['dist/migrations/*{.ts,.js}'],
  autoLoadEntities: true,
  synchronize: false,
};

export default registerAs('datasource', () => config);
export const connectionSource = new DataSource(config as DataSourceOptions);

Sample of a class

typescript
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, OneToMany, ManyToOne } from 'typeorm';

@Entity('Categories')
export class Category {
  ...
}

commands used:

json
{
    "typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli",
    "typeorm:create-migration": "npm run typeorm -- migration:generate -d ./src/configuration/data-source-cli.ts ./src/migrations/migration",
    "typeorm:run-migrations": "npm run typeorm -- migration:run -d src/configuration/data-source-cli.ts",
 }

My Environment

Dependency Version
Operating System Win 11
Node.js version 20.18.0
Typescript version 5.8.2
TypeORM version 0.3.21

Additional Context

When I remove the name in the entity decorator, It works fine :/

Relevant Database Driver(s)

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

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

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.