Search code examples
ruby-on-railsimportadminrails-admin

Rails admin import fails with belongs to relation


I'm using rails 6, rails admin and rails_admin_import

I want to import some data via CVS to my app, this is my Model:

class Contact < ApplicationRecord
  belongs_to :list
end

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

and this is an example of my CVS file Structure:

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

but When I import the file I have this result:

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

I've tryed with diferents headers for my CVS file, but I had the same result:

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

EDIT:

I found my problem, I need to use , not ; in my CVS file....

but with that change I get this issue:

Error during import: List(#70256226968860) expected, got # which is an instance of List(#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!')


Solution

  • Well I found the solution Here: https://github.com/stephskardal/rails_admin_import/issues/88

    I only needed to restart the server