【发布时间】:2017-12-21 14:52:28
【问题描述】:
以下是我从主数据库向关联模型中添加数据时遇到的错误。
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: 错误: 在表“配置”上插入或更新违反外键 约束“fk_rails_29e23e6ceb”详细信息:键(company_id)=(129)是 不存在于表“公司”中。
【问题讨论】:
-
分享你的模型架构..
-
Company has_many :configurations Configuration belongs_to :company `` 公司模型被排除在租户之外,并且配置模型在租户中```
-
schema在表列和数据类型中,而不是associations.. -
** create_table "configurations", force: :cascade do |t| t.string "key" t.string "value" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "catelog_source_id" t.boolean "visible", 默认: true t.整数“company_id” t.index [“catelog_source_id”],名称:“index_configurations_on_catelog_source_id”,使用::btree t.index [“company_id”],名称:“index_configurations_on_company_id”,使用::btree end
-
This answer 似乎表明这是不可能的。
标签: ruby-on-rails postgresql activerecord apartment-gem