mysql> alter table student_course
-> add constraint FKq7yw2wg9wlt2cnj480hcdn6dq
-> foreign key (student_id)
-> references student (id);
show create table student_course;
| student_course | CREATE TABLE `student_course` (
`student_id` bigint(20) NOT NULL,
`course_id` bigint(20) NOT NULL,
KEY `FKejrkh4gv8iqgmspsanaji90ws` (`course_id`),
KEY `FKq7yw2wg9wlt2cnj480hcdn6dq` (`student_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
原因 > ストレージエンジンがMySAMになってた
MySAMだとforeign keyがつかないのでInnoDBにする
spring bootの設定
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect