使用关联的 (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
是排除模型的 foreign_key (ContractType)
报告错误来自此行:
@connection.exec_prepared(stmt_key, type_casted_binds.map { |_, val| val })
我正在使用带有该config.use_schemas = true
选项的 postgres。