所以我在使用 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)