JanuszFrontEnd'u
JanuszFrontEnd'u

Reputation: 471

Unknown database - [TypeOrmModule] Unable to connect to the database

I'm writing my first project with Nestjs and I'm having trouble connecting to the database. I installed mysql and set up the connection. TypeOrm creates the database itself? or do i have to do it with mysql?

Nest] 13684   - 07/24/2020, 12:44:50 AM   [TypeOrmModule] Unable to connect to the database. Retrying (1)... +42ms
Error: ER_BAD_DB_ERROR: Unknown database 'my-database'

app.module.ts

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      username: 'root',
      password: 'password',
      database: 'my-database',
      entities: [User],
      synchronize: true,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
}) 

Upvotes: 4

Views: 5800

Answers (2)

Levente
Levente

Reputation: 61

First you should create the my-database database in your mysql server.

The TypeOrmModule create only tables (in in first time.)

  1. Create database in your mysql server: CREATE DATABASE myDatabase; (I recommend, use this format: myDatabase.)
  2. Restart the Nestjs.

That's it!

Upvotes: 6

cojack
cojack

Reputation: 2630

TypeOrm creates the database itself?

nope

or do I have to do it with mysql?

yes

Upvotes: 3

Related Questions