小编kl_*_*333的帖子

无法连接到数据库 - NEST.JS 和 TypeORM

所以我在使用 typeorm 和 postgres 连接到 Nest.js 中的数据库时遇到问题。我的本地 postgres 实例在 docker 上运行。但是当我通过纱线启动运行应用程序时,它会抛出该错误:

[Nest] 12736   - 2020-08-05 10:05:22   [TypeOrmModule] Unable to connect to the database. Retrying (1)... +86ms 
QueryFailedError: no schematic representation of the creation of the object was indicated
Run Code Online (Sandbox Code Playgroud)

我的主要应用程序模块

@Module({
  imports: [TypeOrmModule.forRoot(configService.getTypeOrmConfig()), UsersModule, LoginModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)

我的配置

  public getTypeOrmConfig(): TypeOrmModuleOptions {
    return {
      type: 'postgres',
      host: this.getValue('POSTGRES_HOST'),
      port: parseInt(this.getValue('POSTGRES_PORT')),
      username: this.getValue('POSTGRES_USER'),
      password: this.getValue('POSTGRES_PASSWORD'),
      database: this.getValue('POSTGRES_DATABASE'),
      entities: [__dirname + "/../**/*.entity{.ts,.js}"],
      synchronize: true,
    };
  } …
Run Code Online (Sandbox Code Playgroud)

postgresql node.js docker typeorm nestjs

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

docker ×1

nestjs ×1

node.js ×1

postgresql ×1

typeorm ×1