Nestjs

<Error> prisma 스키마 변경 중 오류 발생

Summer-Jin 2025. 5. 31. 17:37

 

 

프로젝트를 진행하다가 기획 회의중 db 변경사항이 발생했다.

prisma.schema를 변경하고 마이그레이트를 했더니 다음과 같은 오류 발생

더보기

 

Error: 
⚠️ We found changes that cannot be executed:

  • Step 5 Added the required column `cafe_category` to the `Cafeteria` table without a default value. There are 6 rows in this table, it is not possible to execute this step.
  • Step 5 Added the required column `cafe_stadiumId` to the `Cafeteria` table without a default value. There are 6 rows in this table, it is not possible to execute this step.

You can use prisma migrate dev --create-only to create the migration file, and manually modify it to address the underlying issue(s).
Then run prisma migrate dev to apply it and verify it works.

테스트용 더미데이터를 넣어놓은 상태에서 컬럼을 추가하려고 해서 발생한 오류로 

난 nullable로 일단 마이그레이트 한다음 나중에 not null로 바꾸기로 했다ㅋㅋㅋ...

에셋을 수집해서 blob starage url을 따다가 집어 넣어둔거에 시간대 별로 데이터가 바뀌는 크롤링 데이터들이라 

데이터를 따올 시간까지 기다리기 싫어서 이렇게 조치했다.

 

데이터타입? 이렇게 ? 을 붙여서 nullable로 지정해준다음 

 

npx prisma migrate dev

 

명령어를 입력하면 이렇게 물어본다

- 님 진짜 이거 적용할거임?? 

 

yes 해준다음 자기가 쓰는 db에 들어가서 데이터 null이 들어가있는 컬럼에 값을 다 넣어주고 

nullable을 지운다음 다시 마이그레이트 하면 된다.

728x90