how do i load a csv file in rails from a migrate usiing load data local infile ?

Posted by Chris Drappier on Stack Overflow See other posts from Stack Overflow or by Chris Drappier
Published on 2010-03-29T19:27:17Z Indexed on 2010/03/30 18:43 UTC
Read the original article Hit count: 458

Filed under:
|
|
|

Hi All,

I have my csv file in my public folder, and i'm trying to load it from a migration, but I get a file not found error using this script :

ActiveRecord::Base.connection.execute(
  "load data local infile '#{RAILS_ROOT}/public/muds_variables.csv' into table muds_variables " +
  "fields terminated by ',' " +
  "lines terminated by '\n' " +
  "(variable_name, definition)")

I've checked and re-checked the file path, and that's definitely where it lives, I've also tried it just using the file name without any of the path, and a few other combos, but I can't make it work :(. can anyone help me out with this?

here's the error : Mysql::Error: File '/home/chris/rails_projects/muds/public/muds_variables.csv' not found (Errcode: 2): load data local infile '/home/chris/rails_projects/muds/public/muds_variables.csv' into table muds_variables fields terminated by ',' lines terminated by ' ' (variable_name, definition)

-C

© Stack Overflow or respective owner

Related posts about mysql

Related posts about csv