简体   繁体   English

如何使用加载数据本地infile从迁移中将csv文件加载到rails中?

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

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 : 我的公用文件夹中有csv文件,并且正在尝试从迁移中加载它,但是使用此脚本却出现文件找不到错误:

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) 这是错误:Mysql :: Error:找不到文件'/home/chris/rails_projects/muds/public/muds_variables.csv'(错误代码:2):加载数据本地文件'/ home / chris / rails_projects / muds / public / “ muds_variables.csv”到表以“”结尾的“ muds_variables”字段,以“”结尾的行(variable_name,定义)

-C -C

答案是,如果您实际上有一个名为muds_variables.csv的文件,则此方法应该起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM