gpt4 book ai didi

ruby-on-rails - 公寓 gem 的外键问题

转载 作者:行者123 更新时间:2023-11-29 11:47:45 25 4
gpt4 key购买 nike

关联(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) 的外键

报告的错误来自这一行:

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

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

最佳答案

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

关于ruby-on-rails - 公寓 gem 的外键问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29478987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com