###前提・実現したいこと
タイトルのようにPostgreSQLにてパーティショニングしたテーブルを外部キーにすることを目指していいますが、エラーが出てしまいうまくいきません。
###発生している問題・エラーメッセージ
テーブルcompoundsのcompound_idを外部キーとしてテーブルbit_fingerprintsを紐付けることを目指していますが下に示すようにエラーが出てしまいます。
sql
1ALTER TABLE all_now.bit_fingerprints ADD FOREIGN KEY (compound_id) REFERENCES all_now.compounds (compound_id); 2ERROR: insert or update on table "bit_fingerprints" violates foreign key constraint "bit_fingerprints_compound_id_fkey" 3DETAIL: Key (compound_id)=(35) is not present in table "compounds".
テーブルcompoundsはcompound_idでパーティショニングを行っており実際のデータは子テーブルのcompounds_200000, compounds_400000...に入っています。
###試したこと
StackOverFlowの記事を参考にしたところ親テーブルを外部キーとしたらよさそうに思えたのですが、今回の件ではまた別なのでしょうか?(出力結果は上の画像やコードになります)
子テーブルを外部キーとすることも試していますがその場合はcompounds_200000に含まれないcompound_idのレコードに対して以下のエラーが出てしまいます。
sql
1ALTER TABLE all_now.bit_fingerprints ADD FOREIGN KEY (compound_id) REFERENCES all_now.compounds_200000 (compound_id); 2ERROR: insert or update on table "bit_fingerprints" violates foreign key constraint "bit_fingerprints_compound_id_fkey" 3DETAIL: Key (compound_id)=(200013) is not present in table "compounds_200000".
###バージョン情報
PostgreSQL (version9.5.7)
ご助言いただけたら幸いです。よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー