[ T I L ] 2024.03.04

오세창·2024년 3월 3일

TIL

목록 보기
6/18

문제

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL

...

references menu (id)" via JDBC [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option 
       add constraint FK34xcbhg63bh8t429wslux64lg 

메뉴의 옵션을 추가하는 기능을 구현하기 위해 "option" 테이블을 생성하려고 했지만 위와 같은 에러가 발생했다.

    create table option (
        id bigint not null auto_increment,
        content varchar(255) not null,
        price integer not null,
        menu_id bigint,
        primary key (id)
    ) engine=InnoDB" via JDBC [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option (
        id bigint not null auto_increment,
        content varchar(255)' at line 1

이처럼 create 문까지 나가는 건 확인했지만, 해당 이름의 테이블은 생성할 수 없는 거 같다.

시도

수정 전

@Table(name = "option")

수정 후

@Table(name = "menu_option")

이에 테이블 이름을 변경해주었다.

해결

    create table menu_option (
        id bigint not null auto_increment,
        content varchar(255) not null,
        price integer not null,
        menu_id bigint,
        primary key (id)
    ) engine=InnoDB

문제 없이 테이블 생성에 성공했다 !!

알게된 점

테이블 생성할 때 예약어는 테이블 명으로 쓸 수 없다는 건 알았지만, option 도 이에 해당하지는 못했다.

이 기회에 테이블 생성 시 예약어로 구성된 이름은 사용하지 않는 것에 대해 더 경각심을 가지게 되었다.

0개의 댓글