【问题标题】:Rails admin import fails with belongs to relationRails 管理员导入失败,属于关系
【发布时间】:2020-02-21 20:14:03
【问题描述】:

我正在使用 rails 6、rails admin 和 rails_admin_import

我想通过 CVS 将一些数据导入我的应用程序,这是我的模型:

class Contact < ApplicationRecord
  belongs_to :list
end

class List < ApplicationRecord
  has_many :contacts, dependent: :destroy
end

这是我的 CVS 文件结构的示例:

Name;Phone;list_id
Ali Cate;+573133333333;1
Alan Brito;+5733333333;1

但是当我导入文件时,我得到了这个结果:

Failed to create : List must exist
Failed to create : List must exist

我尝试为我的 CVS 文件使用不同的标头,但结果相同:

Name;Phone;list
Name;Phone;list id
Name;Phone;id

编辑:

我发现了我的问题,我需要使用 ,而不是 ;在我的 CVS 文件中......

但是有了这个改变,我遇到了这个问题:

导入时出错:预期为 List(#70256226968860),得到 # 这是 列表(#70256206360100) (.rvm/gems/ruby-2.6.5/gems/activerecord-6.0.2.1/lib/active_record/associations/association.rb:287:in `raise_on_type_mismatch!')

【问题讨论】:

    标签: ruby-on-rails import admin rails-admin


    【解决方案1】:

    我在这里找到了解决方案:https://github.com/stephskardal/rails_admin_import/issues/88

    我只需要重启服务器

    【讨论】:

      猜你喜欢
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-10
      • 2015-09-27
      • 2014-10-09
      • 2020-08-20
      相关资源
      最近更新 更多