Reputation: 471
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
Reputation: 61
First you should create the my-database
database in your mysql server.
The TypeOrmModule create only tables (in in first time.)
CREATE DATABASE myDatabase;
(I recommend, use this format: myDatabase
.)That's it!
Upvotes: 6
Reputation: 2630
TypeOrm creates the database itself?
nope
or do I have to do it with mysql?
yes
Upvotes: 3