Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

953
Vistas
Setting up typeorm with nestjs not working migrations

Here is the config:

@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        type: 'postgres',
        host: configService.get('DB_HOST'),
        port: configService.get('DB_PORT'),
        username: configService.get('DB_USER'),
        password: configService.get('DB_PASSWORD'),
        database: configService.get('DB_NAME'),
        entities: [
          __dirname + '/../**/*.entity{.ts,.js}',
        ],
        // synchronize: true,
      })
    }),
  ],
})
export class DatabaseModule {}

The connections with the database itself is working, but when I'm trying to set up the migrations it throws the errors. What I've tried is to add the migration options in the above config and to create additional ormconfig.js with the configurations. Here is what I have in package.json file:

"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"

The problem is when I try to create migration it is not being created in migrations folder as I want and is not using the config above, how to solve it?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

If you're using typeorm or 3.0 or newer versions you should do it straight on the cli:

typeorm migration:create src/migration_path

For older versions, you can add the following command to the ormconfig file:

  "cli": {
    "migrationDir": "./src/migration_path"
  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

First, you need to set the migrations path in the module config

TypeOrmModule.forRootAsync({
    // other properties
    entities: [
      __dirname + '/../**/*.entity{.ts,.js}', // from the question
    ],
    migrations:[/*I assume you already know migration file paths*/]
})

then, To generate a migration file

npx typeorm migration:create -n FileName -d src/migrations

At this point, you need to call runMigrations(). add the below code in your main.ts

const conn = await getConnection('default'); // connection name is "default"
await conn.runMigrations();
about 4 years ago · Juan Pablo Isaza Denunciar

0

TypeORM CLI reads the configuration in a file ormconfig.json or ormconfig.js at the root of the project.

You need to extract this config in suck a file and then import this file in your DatabaseModule to have both things working.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda