다음의 상황을 한번 보도록 하자
// test.controller.ts
@Get()
getTest() {
return this.testService.getTest();
}
@Get()
getTestById(
@Query('id') id: string
) {
return this.testService.getTestById(id);
}
위와 같이 작성할 경우, getTest
로 요청이 들어가기 때문에 getTestById
에 접근이 불가능하다.
따라서, 아래와 같이 순서를 정의해두어야 두 요청 모두 사용이 가능하니 유의하도록 하자
// test.controller.ts
@Get()
getTestById(
@Query('id') id: string
) {
return this.testService.getTestById(id);
}
@Get()
getTest() {
return this.testService.getTest();
}
app.module.ts
를 보자
당신의 app.module.ts
TypeOrmModule
옵션에 synchronize: true
가 있을 것이다.
신기한가? 난 신기했는데
synchronize
옵션은 app 을 실행할 때마다 TypeOrm
이 새로운 table 을 만든다.
이로 인해서 위와 같은 에러가 발생했던 것이다.
synchronize - Indicates if database schema should be auto created on every application launch. Be careful with this option and don't use this in production - otherwise you can lose production data. This option is useful during debug and development. As an alternative to it, you can use CLI and run schema:sync command. Note that for MongoDB database it does not create schema, because MongoDB is schemaless. Instead, it syncs just by creating indices.