오류 원인
MySQL에서 drop table로 테이블 삭제 시, 다른 테이블에 외래키가 걸려있다고 삭제가 되지 않는 경우이다.
하지만 drop table 쿼리 명령을 하지 않았는데 왜 테이블이 삭제된다고 하지?? 라는 의문이 있었는데... 원인을 찾았다.
application.properties
spring.jpa.hibernate.ddl-auto=create
이 부분이 create로 설정되어 있었다.
create는 애플리케이션을 실행할 때 마다 모든 테이블을 제거하고 다시 생성하기 때문에, 이 부분에서 오류가 났다.
몇가지 옵션이 있는데, 어떤 것으로 설정할지는 개발자의 자유다.
표로 옵션을 알아보자.
create | 애플리케이션 실행 시 모든 테이블을 제거하고 다시 생성합니다. |
create-drop | 애플리케이션 실행 시 모든 테이블을 제거하고 다시 생성합니다. 애플리케이션 종료시 모든 테이플을 제거합니다. |
update | 애플리케이션 실행 시 변경된 사항만 적용합니다. |
validate | 현재 테이블 정보가 entity에 정의된 내용과 동일한지 체크합니다. 다르다면 경고를 하며 애플리케이션을 실행 하지 않습니다. |
none | 자동생성을 사용하지 않습니다. |
오류 해결
옵션을 update로 해주니 해결이 되었다!
spring.jpa.hibernate.ddl-auto=update
틀린부분이 있으면 지적해주시면 감사하겠습니다.
Reference
'Server' 카테고리의 다른 글
[JPA] 영속성 컨텍스트 #2 (0) | 2024.08.08 |
---|---|
[SpringBoot] Entity 생성하기 / JPA 간단한 예제 (0) | 2024.08.07 |
[JPA] JPA란 / 영속성 컨텍스트 #1 (0) | 2024.08.02 |
[JPA] GenerationType.IDENTITY 오류 / AUTO_INCREMENT (0) | 2024.08.02 |
DDD 개념 / DAO와 Repository 차이 (0) | 2024.07.31 |