質問編集履歴
1
全体
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
railsでデータを削除できません。
|
test
CHANGED
@@ -1,37 +1,29 @@
|
|
1
1
|
```ここに言語を入力
|
2
2
|
|
3
|
-
PG::
|
4
|
-
|
5
|
-
LINE 5: WHERE a.attrelid = '"categories_people_people...
|
6
|
-
|
7
|
-
^
|
8
|
-
|
9
|
-
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
|
10
|
-
|
11
|
-
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
|
12
|
-
|
13
|
-
FROM pg_attribute a LEFT JOIN pg_attrdef d
|
14
|
-
|
15
|
-
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
|
16
|
-
|
17
|
-
WHERE a.attrelid = '"categories_people_people"'::regclass
|
18
|
-
|
19
|
-
AND a.attnum > 0 AND NOT a.attisdropped
|
20
|
-
|
21
|
-
ORDER BY a.attnum
|
3
|
+
PG::ForeignKeyViolation: ERROR: update or delete on table "people" violates foreign key constraint "fk_rails_c7c0232d36" on table "categories_people" DETAIL: Key (id)=(2) is still referenced from table "categories_people". : DELETE FROM "people" WHERE "people"."id" = $1
|
22
4
|
|
23
5
|
```
|
24
6
|
|
25
7
|
|
26
8
|
|
27
|
-
上記の
|
9
|
+
上記のようなエラーが出ました。
|
28
10
|
|
29
|
-
```ここに言語を入力
|
30
11
|
|
31
|
-
WHERE a.attrelid = '"categories_people_people"'::regclass
|
32
12
|
|
33
|
-
|
13
|
+
personとperiodとcategoryの3つのテーブルがあります。
|
34
14
|
|
35
|
-
|
15
|
+
そして、personと同時にperiodとcategoryを登録できるようになっています。
|
36
16
|
|
37
|
-
|
17
|
+
personとperiod、personとcategoryが紐付けされている2つの中間テーブルが存在しています。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
中間テーブルにデータを送って登録や変更をすることはできているんですが、データを削除することができません。削除しようとするとエラーが出ます。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
多分modelの設定が間違ってると思うんですが、どうすればいいかわかりません。
|
26
|
+
|
27
|
+
中間テーブルは、belongs_toを使っています。
|
28
|
+
|
29
|
+
それ以外は、has_manyやthroughを使っています。
|