質問編集履歴

1

いただいた回答をもとに再度実行してみました。

2017/01/23 15:26

投稿

kazuhihi
kazuhihi

スコア20

test CHANGED
File without changes
test CHANGED
@@ -1,10 +1,86 @@
1
1
  ###前提・実現したいこと
2
2
 
3
- mysqlて下記コードを実行したのですがなぜが原因がわません。
3
+ いただいた回答をもと再度実行したのですがなかなかうくいきません。
4
+
5
+ 実行したsql全文添付します。
4
6
 
5
7
 
6
8
 
9
+ DROP TABLE IF EXISTS meeting_room CASCADE;
10
+
11
+ DROP TABLE IF EXISTS reserbable_room CASCADE;
12
+
13
+ DROP TABLE IF EXISTS reservatio CASCADE;
14
+
15
+ DROP TABLE IF EXISTS usr CASCADE;
16
+
17
+
18
+
19
+ CREATE TABLE IF NOT EXISTS meeting_room(
20
+
21
+ room_id SERIAL NOT NULL PRIMARY KEY,
22
+
23
+ room_name VARCHAR(255) NOT NULL
24
+
25
+ );
26
+
27
+
28
+
29
+ CREATE TABLE IF NOT EXISTS reservable_room(
30
+
31
+ reserved_date DATE NOT NULL,
32
+
33
+ room_id INT4 NOT NULL,
34
+
35
+ PRIMARY KEY(reserved_date,room_id)
36
+
37
+ );
38
+
39
+ CREATE TABLE IF NOT EXISTS reservation(
40
+
41
+ reservation_id SERIAL NOT NULL PRIMARY KEY,
42
+
43
+ end_time TIME NOT NULL,
44
+
45
+ start_time TIME NOT NULL,
46
+
47
+ reservel_date DATE NOT NULL,
48
+
49
+ roomid INT4 NOT NULL,
50
+
51
+ user_id VARCHAR(255) NOT NULL
52
+
53
+ );
54
+
55
+
56
+
57
+ CREATE TABLE IF NOT EXISTS usr(
58
+
59
+ user_id VARCHAR(255) NOT NULL PRIMARY KEY,
60
+
61
+ first_name VARCHAR(255) NOT NULL,
62
+
63
+ last_name VARCHAR(255) NOT NULL,
64
+
65
+ password VARCHAR(255) NOT NULL,
66
+
67
+ role_name VARCHAR(255) NOT NULL
68
+
69
+ );
70
+
7
- ALTER TABLE reservable_room ADD CONSTRAINT FK_f4wnx2qj0d59s9tl1q5800fw7 FOREIGN KEY(room_id);
71
+ ALTER TABLE reservable_room ADD CONSTRAINT FK_f4wnx2qj0d59s9tl1q5800fw7 FOREIGN KEY(room_id) REFERENCES meeting_room(room_id);
72
+
73
+ ALTER TABLE reservation ADD CONSTRAINT FK_p1k4iriqd4eo1cpnv79uvni9g FOREIGN KEY (reserved_date,room_id) REFERENCES reservable_room;
74
+
75
+ ALTER TABLE reservation ADD CONSTRAINT FK_recqnfjcp370rygd9hjjxjtg FOREIGN KEY (user_id) REFERENCES usr;
76
+
77
+
78
+
79
+ 下記がエラー文なのですが
80
+
81
+ なぜ”Cannot add foreign key constraint”になるのかが不明です。
82
+
83
+
8
84
 
9
85
 
10
86
 
@@ -12,7 +88,7 @@
12
88
 
13
89
 
14
90
 
15
- ERROR 1064 (42000): 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 '' at line 1
91
+ Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceInitializer': Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #9 of URL [file:/Users/kazuanzo/Documents/Reservation/mrs/target/classes/schema.sql]: ALTER TABLE reservable_room ADD CONSTRAINT FK_f4wnx2qj0d59s9tl1q5800fw7 FOREIGN KEY(room_id) REFERENCES meeting_room(room_id); nested exception is java.sql.SQLException: Cannot add foreign key constraint
16
92
 
17
93
 
18
94