인프런 커뮤니티 질문&답변

dch3030님의 프로필 이미지
dch3030

작성한 질문수

Slack 클론 코딩[백엔드 with NestJS + TypeORM]

typeorm seeding, migration

npm run db:create

작성

·

496

·

수정됨

0

import { DataSource } from 'typeorm'; import dotenv from 'dotenv'; import { ChannelChats } from './src/entities/ChannelChats'; import { ChannelMembers } from './src/entities/ChannelMembers'; import { Channels } from './src/entities/Channels'; import { DMs } from './src/entities/DMs'; import { Mentions } from './src/entities/Mentions'; import { Users } from './src/entities/Users'; import { WorkspaceMembers } from './src/entities/WorkspaceMembers'; import { Workspaces } from './src/entities/Workspaces'; dotenv.config(); const dataSource = new DataSource({ type: 'mysql', host: 'localhost', port: 3306, username: process.env.DB_USERNAME, password: process.env.DB_PASSWORD, database: process.env.DB_DATABASE, entities: [ ChannelChats, ChannelMembers, Channels, DMs, Mentions, Users, WorkspaceMembers, Workspaces, ], migrations: [__dirname + '/src/migrations/*.ts'], charset: 'utf8mb4_general_ci', synchronize: false, logging: true, }); export default dataSource;

 

에러!

Error: Can't add new command when connection is in closed state

at Connection._addCommandClosedState (/Users/minchankim/Desktop/study/nestToy/node_modules/mysql2/lib/connection.js:148:17)

at Connection.end (/Users/minchankim/Desktop/study/nestToy/node_modules/mysql2/lib/connection.js:855:26)

at Query.onResult (/Users/minchankim/Desktop/study/nestToy/node_modules/typeorm-extension/dist/database/driver/mysql.js:27:28)

at Connection._notifyError (/Users/minchankim/Desktop/study/nestToy/node_modules/mysql2/lib/connection.js:228:17)

at Connection._handleFatalError (/Users/minchankim/Desktop/study/nestToy/node_modules/mysql2/lib/connection.js:167:10)

at Connection._handleNetworkError (/Users/minchankim/Desktop/study/nestToy/node_modules/mysql2/lib/connection.js:180:10)

at Socket.emit (node:events:513:28)

at Socket.emit (node:domain:489:12)

at emitErrorNT (node:internal/streams/destroy:151:8)

at emitErrorCloseNT (node:internal/streams/destroy:116:3) {

fatal: true

}

계속 이렇게 나오는데 npm run db:create
데이터베이스 정보확인 및 dotenv도 재설치 해봤는데 계속 안되서 질문드립니다!버전에 문제가 있나 싶어서 강사님 package.json에서 그대로 불러왔습니다!

답변 1

0

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

정상 작동하는 것 확인했습니다. .env 값들 확인해보세요.

dch3030님의 프로필 이미지
dch3030
질문자

"localhost"로 하니깐 안되다가 "127.0.0.1"로하니깐 이제서야 되네요.. 감사합니다

dch3030님의 프로필 이미지
dch3030

작성한 질문수

질문하기