From: John Mcleod Date: 2009-07-17T00:37:28+09:00 Subject: Re: CSV file to database problem - FasterCSV::MalformedCSVError Solved my own problem. Found an import script at http://espndev.com/blog/csv-imports-using-fastercsv/ Here it is: require 'fastercsv' class LoadRatingsData < ActiveRecord::Migration def self.up FasterCSV.foreach("#{RAILS_ROOT}/db/migrate/fixtures/ratings.csv", :row_sep => "\r") do |row| id,game_id, region_id, rating, duration = row Rating.create(:id => id, :game_id => game_id, :region_id => region_id, :rating => rating, :duration => duration) end end def self.down end end I updated all table/column info. for my database info. Regards, JohnM John Mcleod wrote: > Hello all, > > I'm having problems importing a simple csv into the sqlite database. > > When I execute "db:migrate --trace", I get > "FasterCSV::MalformedCSVError". I've check the .csv file and made sure > that it's UTF-8 encoded. > > Here's my migration file: > > require 'faster_csv' > class AddTestData < ActiveRecord::Migration > > def self.up > Project.delete_all > array_of_arrays = FasterCSV.foreach('filename.csv') do |row| > > record = Project.new( > :irb_number => row[0], > :pi_full_name => row[1], > :cr_quest_split => row[2], > :cr_and_ct_split => row[3], > :old_master_list => row[4], > :title => row[5], > :status_of_irb => row[6], > :expiration_date => row[7], > :review_level => row[8], > :category => row[9], > :q2_study_coordinator_last_name => row[10], > :q2_study_coordinator_first_name => row[11] > ) > record.save > > end > end > > "Projects" is the name of the table and all of the symbols are columns > within the table. > > Any help or a pointer to a good example is appreciated. > > Thanks, > JohnM -- Posted via http://www.ruby-forum.com/.