title: Import CSV to existing sqlite database table
body: <p>I've searched all over this forum for solution to the above problem, but everything I tried didn't work. Basically, i have a model Library, with corresponding libraries table in my sqlite3 database. I have a csv file named libraries.csv which contains all the data I want to import into the database. </p>
  
  <p>I tried the method on the second answer on <a href="https://stackoverflow.com/questions/12461260/how-can-i-import-a-csv-file-via-a-rake-task">this page</a> but it's still not working. I made sure to create my rake file 'import_libraries.rake in the lib/tasks folder and I also saved the libraries.csv file in that folder but i keep getting this error message:</p>
  
  <blockquote>
    <p>rake aborted!<br>
    Don't know how to build task 'import_libraries' (See
    full trace by running task with --trace)</p>
  </blockquote>
  
  <p>This is the current code I'm using:</p>
  
  <pre><code>require 'csv'
  desc "Imports a CSV file into an ActiveRecord table"
  task :import, [:filename] =&gt; :environment do    
      CSV.foreach('libraries.csv', :headers =&gt; true) do |row|
        Library.create!(row.to_hash)
      end
  end
  </code></pre>
  
  <p>But when I run bundle exec rake import_libraries, I get the error message above.</p>
  
  <p>Is there anything I am doing wrong? i would appreciate your help guys. Thanks</p>
  
  <p><em>EDIT</em></p>
  
  <p>I renamed the rake file from import_libraries.rake to just import.rake On running bundle exec rake import, the error message i now get is:</p>
  
  <blockquote>
    <p>rake aborted! invalid byte sequence in UTF-8
    C:/Users/username/rails_app_name/lib/tasks/import.rake:4:in `block in
    ' Tasks: TOP => import (See full trace by running task
    with --trace)</p>
  </blockquote>