2017-07-17 48 views
0

以下是我在從主數據庫關聯模型中添加數據時得到的錯誤。公寓寶石的外鍵問題是否有任何其他解決方案在關聯表中插入數據

ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "configurations" violates foreign key constraint "fk_rails_29e23e6ceb" DETAIL: Key (company_id)=(129) is not present in table "companies".

+0

共享你的模型架構.. –

+0

公司 的has_many:配置 配置 belongs_to的:公司 '''公司模式被排除在租戶和配置模型在tenent''' –

+0

'schema'如表中的列和數據類型,而不是「association」。 –

回答

0

我有同樣的問題,並花了很多時間試圖找出造成這種情況的原因。 解決方案很簡單(至少在我的情況下)。從創業板的文檔 直:

If you have some models that should always access the 'public' tenant, you can specify this by configuring Apartment using Apartment.configure. This will yield a config object for you. You can> set excluded models like so:

config.excluded_models = ["User", "Company"]  # these models 
will not be multi-tenanted, but remain in the global (public) 
namespace ``` 

所以只是將它加入你的apartment.rb文件。

Apartment.configure do |config| 
    config.excluded_models = %w{ User Company } 
    ... 
end 
相關問題