Foreign key issues with Apartment gem

亡梦爱人 提交于 2020-07-19 05:21:37

问题


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"

In this case, contract_type_id is a foreign_key to an excluded model (ContractType)

The error is reported to have come from this line:

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

I am using postgres with the config.use_schemas = true option.


回答1:


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.



来源:https://stackoverflow.com/questions/29478987/foreign-key-issues-with-apartment-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!