Apartment gem的外键问题

时间:2015-04-06 20:19:37

标签: ruby-on-rails postgresql apartment-gem

使用关联(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 })

我正在使用带有config.use_schemas = true选项的postgres。

1 个答案:

答案 0 :(得分:2)

如果我正确理解您的模型关系,this may help readers understand the problem。简短:公寓不支持非排除模型与排除模型之间的外键约束。