Debug

[Hibernate][MySQL] org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL " alter table Reply add constraint FKr5xsgtav636xcqpjh0j81wb2n foreign key ('boardId') references Board (id)" via JDBC Statement

배게 2022. 3. 5. 06:49
728x90
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "
    alter table Reply 
       add constraint FKr5xsgtav636xcqpjh0j81wb2n 
       foreign key ('boardId') 
       references Board (id)" via JDBC Statement
Caused by: java.sql.SQLSyntaxErrorException: 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 ''userId') 
       references User (id)' at line 3​

 

 

 

 

 

연관관계 설정하는 부분에서 자꾸 에러가남

 

@JoinColumn의 name = 부분의 " 'userId' " 이 부분을

name = "userId"로 바꿔줘야함 이건 컬럼의 데이터 값이 아니라 필드값이라서 ' '를 붙이면 안됨

 

' '를 붙여야하는 어노테이션은 

ex) @ColumnDefault("'user'")

 

 

 

 

 

 

blog DB의 reply Table에 foreign Key로 boardId와 userId가 제대로 설정돼있음

댓글수0