Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

6.5K
Views
No se puede conectar a la base de datos - NEST.JS y TypeORM

Así que tengo un problema con la conexión a la base de datos en nest.js con typeorm y postgres. Tengo mi instancia local de postgres ejecutándose en docker. Pero cuando estoy ejecutando la aplicación por hilo, arroja ese error:

 [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

Mi módulo de aplicación principal

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

mi configuración

 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, }; }

Mi archivo env

 POSTGRES_HOST=127.0.0.1 POSTGRES_PORT=5432 POSTGRES_USER=postgres POSTGRES_PASSWORD=kacluk123 POSTGRES_DATABASE=my_database PORT=3000 MODE=DEV

Script para ejecutar docker/postgres

 #!/bin/bash set -e SERVER="my_database_server"; PW="kacluk123"; DB="my_database"; echo "echo stop & remove old docker [$SERVER] and starting new fresh instance of [$SERVER]" (docker kill $SERVER || :) && \ (docker rm $SERVER || :) && \ docker run --name $SERVER -e POSTGRES_PASSWORD=$PW \ -e PGPASSWORD=$PW \ -p 5432:5432 \ -d postgres # wait for pg to start echo "sleep wait for pg-server [$SERVER] to start"; SLEEP 3; # create the db echo "CREATE DATABASE $DB ENCODING 'UTF-8';" | docker exec -i $SERVER psql -U postgres echo "\l" | docker exec -i $SERVER psql -U postgres
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cuando me enfrentaba a este problema en mi proyecto Nestjs y Typeorm, mi problema era que mi base de datos no se creó realmente en mi postgres, por lo que necesitaba crearla. Tenga en cuenta que mi sistema operativo era Linux, seguí estos pasos para eso.

  • sudo su - postgres
  • psql para ingresar a los comandos cli de postgres
  • CREATE DATABASE databaseName;

Tenga en cuenta el punto y coma al final del comando postgres, estos son obligatorios en la sintaxis

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!