#Get error EntityMetadataNotFoundError No metadata was found when use two dbs in a single Nestjs app

5 messages · Page 1 of 1 (latest)

steel oriole
#

Hi I just got this error EntityMetadataNotFoundError: No metadata was found. when run a simple find like this.balanceRepository.find({ })
I have researched but found nothing for this situation .
Have anyone got this error before ?
I'm using Typeorm 0.3x version

Here are my config for these two dbs:

TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
const username = configService.get('timescaledb.user');
const password = configService.get('timescaledb.pass');
const database = configService.get('timescaledb.db');
const host = configService.get('timescaledb.host');
const port = parseInt(configService.get('timescaledb.port'), 10);

    return {
      type: 'postgres',
      host,
      port,
      username,
      password,
      database,
      entities: ['dist/src/modules/**/*.timescaledb.entity.js'],
      migrations: ['migrations/timescaledb/*.js'],
      synchronize: false,
    };
  },
}),
TypeOrmModule.forRootAsync({
  imports: [ConfigModule],
  inject: [ConfigService],
  useFactory: async (configService: ConfigService) => {
    const username = configService.get('postgres.user');
    const password = configService.get('postgres.pass');
    const database = configService.get('postgres.db');
    const host = configService.get('postgres.host');
    const port = parseInt(configService.get('postgres.port'), 10);

    return {
      type: 'postgres',
      host,
      port,
      username,
      password,
      database,
      entities: ['dist/src/modules/**/*.postgres.entity.js'],
      migrations: ['migrations/postgres/*.js'],
      synchronize: false,
    };
  },
}),
sharp vortex
#

hello, not related to your answer but can you please show me how you have done the migrations using datasource?

steel oriole
#

okay mate, I think this youtube link is better show for you .
https://www.youtube.com/watch?v=5G81_VIjaO8&t=520s

In this quick video we go over the basics of setting up and using TypeORM specifically with NestJS. This video covers the newer typeORM 0.3 and above versions which has had some breaking changes from 0.2. We'll cover how to create a CRUD API, how to write SQL queries, and finally how to do migrations.

00:00 - Intro
00:21 - New Nest JS applicati...

▶ Play video
sharp vortex
#

thank for the video but how can i use configservice in data-source.ts? he is just using the params directly without using env.

steel oriole
#

of course. you can use typeOrmModule.forRootAsync . I think Marius uses like that because he just wants to show us to config dataSource for migration quickly.