Prisma 기존 테이블에 새로운 필수 컬럼 추가하기
작성일 : 2025.01.22
문제 상황

Prisma schema에 새로운 필수(required) 컬럼을 추가하고 마이그레이션을 실행할 때, 다음과 같은 에러가 발생할 수 있습니다:
Error:
No found changes that cannot be executed:
• Step 1 Added the required column 'gender' to the 'User' table without a default value. There are 3 rows in this table, it is not possible to execute this step.
이 에러는 이미 데이터가 있는 테이블에 기본값이 없는 필수 컬럼을 추가하려고 할 때 발생합니다.
해결 방법
1. Schema 수정
먼저 schema.prisma 파일에서 새로운 컬럼들에 기본값을 추가합니다:
model User {
id Int @id @default(autoincrement())
email String @unique
password String
role String @default("R001")
nickname String?
gender String @default("") // 기본값 설정
image_url String @default("") // 기본값 설정
provider String @default("local") // 기본값 설정
}