3

関連する (belongs_to) モデルで以下のエラーが発生します。

PG::ForeignKeyViolation: ERROR: insert or update on table "employees" violates foreign key constraint "fk_rails_0d62068e18" DETAIL: Key (contract_type_id)=(2) is not present in table "contract_types". : INSERT INTO "employees" ("title_id", "surname", "othernames", "department_id", "job_title_id", "gender_id", "date_of_birth", "contract_type_id", "employee_status_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id"

この場合、contract_type_id除外されたモデル (ContractType) へのforeign_keyです。

エラーは次の行から発生したと報告されています。

@connection.exec_prepared(stmt_key, type_casted_binds.map { |_, val| val })

オプションでpostgresを使用していconfig.use_schemas = trueます。

4

1 に答える 1

3

モデルの関係を正しく理解できれば、読者が問題を理解するのに役立つかもしれません。要するに、アパートメントは、除外されていないモデルと除外されたモデルの間の外部キー制約をサポートしていません。

于 2016-03-21T20:46:01.613 に答える