質問編集履歴
1
子テーブルに試したエラーも追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
###発生している問題・エラーメッセージ
|
5
5
|
テーブルcompoundsのcompound_idを外部キーとしてテーブルbit_fingerprintsを紐付けることを目指していますが下に示すようにエラーが出てしまいます。
|
6
6
|
|
7
|
-
```
|
7
|
+
```sql
|
8
8
|
ALTER TABLE all_now.bit_fingerprints ADD FOREIGN KEY (compound_id) REFERENCES all_now.compounds (compound_id);
|
9
9
|
ERROR: insert or update on table "bit_fingerprints" violates foreign key constraint "bit_fingerprints_compound_id_fkey"
|
10
10
|
DETAIL: Key (compound_id)=(35) is not present in table "compounds".
|
@@ -14,10 +14,16 @@
|
|
14
14
|
|
15
15
|
テーブルcompoundsはcompound_idでパーティショニングを行っており実際のデータは子テーブルのcompounds_200000, compounds_400000...に入っています。
|
16
16
|
###試したこと
|
17
|
-
[StackOverFlowの記事](https://stackoverflow.com/questions/9597081/postgresql-partitioning-and-fk)を参考にしたところ親テーブルを外部キーとしたらよさそうに思えたのですが、今回の件ではまた別なのでしょうか?
|
17
|
+
[StackOverFlowの記事](https://stackoverflow.com/questions/9597081/postgresql-partitioning-and-fk)を参考にしたところ親テーブルを外部キーとしたらよさそうに思えたのですが、今回の件ではまた別なのでしょうか?(出力結果は上の画像やコードになります)
|
18
18
|
|
19
|
-
子テーブルを外部キーとすることも試していますがその場合はcompounds_200000に含まれないcompound_idのレコードに対してエラーが出てしまいます。
|
19
|
+
子テーブルを外部キーとすることも試していますがその場合はcompounds_200000に含まれないcompound_idのレコードに対して以下のエラーが出てしまいます。
|
20
20
|
|
21
|
+
```sql
|
22
|
+
ALTER TABLE all_now.bit_fingerprints ADD FOREIGN KEY (compound_id) REFERENCES all_now.compounds_200000 (compound_id);
|
23
|
+
ERROR: insert or update on table "bit_fingerprints" violates foreign key constraint "bit_fingerprints_compound_id_fkey"
|
24
|
+
DETAIL: Key (compound_id)=(200013) is not present in table "compounds_200000".
|
25
|
+
```
|
26
|
+
|
21
27
|
###バージョン情報
|
22
28
|
PostgreSQL (version9.5.7)
|
23
29
|
|