質問編集履歴
1
いただいた回答をもとに再度実行してみました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,49 @@
|
|
1
1
|
###前提・実現したいこと
|
2
|
-
|
2
|
+
いただいた回答をもとに再度実行したのですがなかなかうまくいきません。
|
3
|
+
実行したsql全文添付します。
|
3
4
|
|
5
|
+
DROP TABLE IF EXISTS meeting_room CASCADE;
|
4
|
-
|
6
|
+
DROP TABLE IF EXISTS reserbable_room CASCADE;
|
7
|
+
DROP TABLE IF EXISTS reservatio CASCADE;
|
8
|
+
DROP TABLE IF EXISTS usr CASCADE;
|
5
9
|
|
10
|
+
CREATE TABLE IF NOT EXISTS meeting_room(
|
11
|
+
room_id SERIAL NOT NULL PRIMARY KEY,
|
12
|
+
room_name VARCHAR(255) NOT NULL
|
13
|
+
);
|
14
|
+
|
15
|
+
CREATE TABLE IF NOT EXISTS reservable_room(
|
16
|
+
reserved_date DATE NOT NULL,
|
17
|
+
room_id INT4 NOT NULL,
|
18
|
+
PRIMARY KEY(reserved_date,room_id)
|
19
|
+
);
|
20
|
+
CREATE TABLE IF NOT EXISTS reservation(
|
21
|
+
reservation_id SERIAL NOT NULL PRIMARY KEY,
|
22
|
+
end_time TIME NOT NULL,
|
23
|
+
start_time TIME NOT NULL,
|
24
|
+
reservel_date DATE NOT NULL,
|
25
|
+
roomid INT4 NOT NULL,
|
26
|
+
user_id VARCHAR(255) NOT NULL
|
27
|
+
);
|
28
|
+
|
29
|
+
CREATE TABLE IF NOT EXISTS usr(
|
30
|
+
user_id VARCHAR(255) NOT NULL PRIMARY KEY,
|
31
|
+
first_name VARCHAR(255) NOT NULL,
|
32
|
+
last_name VARCHAR(255) NOT NULL,
|
33
|
+
password VARCHAR(255) NOT NULL,
|
34
|
+
role_name VARCHAR(255) NOT NULL
|
35
|
+
);
|
36
|
+
ALTER TABLE reservable_room ADD CONSTRAINT FK_f4wnx2qj0d59s9tl1q5800fw7 FOREIGN KEY(room_id) REFERENCES meeting_room(room_id);
|
37
|
+
ALTER TABLE reservation ADD CONSTRAINT FK_p1k4iriqd4eo1cpnv79uvni9g FOREIGN KEY (reserved_date,room_id) REFERENCES reservable_room;
|
38
|
+
ALTER TABLE reservation ADD CONSTRAINT FK_recqnfjcp370rygd9hjjxjtg FOREIGN KEY (user_id) REFERENCES usr;
|
39
|
+
|
40
|
+
下記がエラー文なのですが
|
41
|
+
なぜ”Cannot add foreign key constraint”になるのかが不明です。
|
42
|
+
|
43
|
+
|
6
44
|
###発生している問題・エラーメッセージ
|
7
45
|
|
8
|
-
|
46
|
+
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
|
9
47
|
|
10
48
|
自分なりに調査したのですが、下記内容が出ました。
|
11
49
|
|