0
DB의 devices 테이블에 devices.csv 파일의 데이터를로드하려고했습니다. 그러나 명령 줄에서 레이크 위의 명령 csv 파일을 업로드하기 위해 import.rake를 실행하는 중 알 수없는 속성 오류가 발생했습니다
rake db:devices RAILS_ENV=production
을 실행하는 동안, 나는 알 수없는 속성을 점점 오전 : 오류가 발생했습니다.
아래는 결과 추적입니다.
** Invoke db:devices (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:devices
rake aborted!
unknown attribute:
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:88:in `block in assign_attributes'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/base.rb:498:in `initialize'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/oink-0.10.1/lib/oink/instrumentation/active_record.rb:60:in `initialize'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/persistence.rb:44:in `new'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/persistence.rb:44:in `create'
/opt/EDDIE/lib/tasks/import.rake:6:in `block (3 levels) in <top (required)>'
/usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/2.0.0/csv.rb:1719:in `each'
/usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/2.0.0/csv.rb:1120:in `block in foreach'
/usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/2.0.0/csv.rb:1266:in `open'
/usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/2.0.0/csv.rb:1119:in `foreach'
/opt/EDDIE/lib/tasks/import.rake:5:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:100:in `top_level'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:78:in `block in run'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
/usr/local/rvm/gems/ruby-2.0.0-p648/gems/rake-10.1.1/bin/rake:33:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p648/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.0.0-p648/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-2.0.0-p648/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.0.0-p648/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:devices
여기에 내 레이크 파일이 lib/tasks 폴더에 있습니다.
require 'csv'
namespace :db do
desc "Import devices from csv file"
task :devices => [:environment] do
CSV.foreach('devices.csv', :headers => true, :encoding => 'ISO-8859-1:UTF-8') do |row|
Device.create(row.to_hash)
end
end
end
누구든지이 오류를 무시하고 DB에 데이터를로드하는 방법을 도울 수 있습니까?
가 작동을 얻었다 :
귀하의 예제를 사용하여,이 같은 될 수 있을까? –
도움을 주셔서 감사합니다. 오류를 추적 할 수 있습니다. 사실 내 CSV 파일에는 DB의 장치 테이블에없는 하나의 추가 열이 포함되어 있습니다. csv 파일에서 해당 열을 제거하면 유용합니다. – Pawan
다음 번 팁을 위해 답변을 업데이트했습니다. –