开发者

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

开发者 https://www.devze.com 2022-12-24 20:38 出处:网络
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 :

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 witho开发者_如何学Gout 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


the answer, is that this should work if you ACTUALLY have a file named muds_variables.csv my file was named muds variables.csv sorry for the waste :/

0

精彩评论

暂无评论...
验证码 换一张
取 消