Apartment gem 的外键问题 [英] Foreign key issues with Apartment gem
本文介绍了Apartment gem 的外键问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在关联(belongs_to)模型时出现以下错误:
Getting the below error with associated (belongs_to) models:
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) 的外键
In this case, contract_type_id
is a foreign_key to an excluded model (ContractType)
报告错误来自这一行:
@connection.exec_prepared(stmt_key, type_casted_binds.map { |_, val| val })
我使用带有 config.use_schemas = true
选项的 postgres.
I am using postgres with the config.use_schemas = true
option.
推荐答案
如果我正确理解你的模型关系,这可能有助于读者理解问题.简短:公寓不支持非排除模型到排除模型之间的外键约束.
If I understand your model relationships correctly, this may help readers understand the problem. The short: Apartment does not support foreign key constraints between non-excluded models to excluded models.
这篇关于Apartment gem 的外键问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文