typeorm을 활용해서 NestJs DB 연결중 생긴 에러
원인
entity를 제대로 찾지 못함
해결방법
TypeOrmMoudule.forRoot부분에 entities 경로를 구조에 맞게 잘 작성
프로젝트 폴더 구조
entities: [__dirname + '/entity/**/*.entity{.ts,.js}',],
이렇게 경로 수정
ERROR [ExceptionHandler] No repository for "EntityName" was found. Looks like this entity is not registered in current "default" connection?
수정 후 이런 에러 발생.
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
@Entity() // 추가
export class Users {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;
@Column('varchar', { name: 'email', unique: true, length: 30 })
email: string;
@Column('varchar', { name: 'nickname', length: 30 })
name: string;
@Column('varchar', { name: 'password', length: 100, select: false })
password: string;
}
@Entity() 데코레이터 추가 후 해결
'🧩Javascript > error' 카테고리의 다른 글
TypeError: Cannot read properties of undefined (reading 'initialize') at bootstrap main.ts (0) | 2022.03.19 |
---|