开发者

Can't migrate .csv file

开发者 https://www.devze.com 2023-02-19 08:19 出处:网络
My migration file: def self.up create_table :geo_data do |t| t.column :zip_code,:string t.column :latitude,:float

My migration file:

    def self.up
create_table :geo_data do |t|
  t.column :zip_code,  :string
  t.column :latitude,  :float
  t.column :longitude, :float
  t.column :city,      :string
  t.column :state,     :string
  t.column :county,    :string
  t.column :type,      :string
end
add_index "geo_data", ["zip_code"], :name => "zip_code_optimization"

csv_file = "#{RAILS_ROOT}/db/migrate/geo_data.csv"
fields = '(zip_code, latitude, longitude, city, state, county)'

execute "LOAD DATA INFILE '#{csv_file}' INTO TABLE geo_data FIELDS " +
        "TERMINATED BY ',' OPTIONALLY ENCLOSED BY \"\"\"\" " +
        "LINES TERMINATED BY '\n' " + fields
end

I am getting this error when I attempt to fill the database with the file:

   Mysql2::Error: Can't get stat of '/home/sean/project/db/migrate/geo_data.csv' (Errcode: 13): LOAD DATA INFILE '/home/sean/project/db/migrate/geo_data.csv' INTO TABLE geo_data FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY '
   ' (zip_code, latitude, longitude, city, state, county)

/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters   /abstract_adapter.rb:207:in `log'
/usr/lib/ruby/gems/1.8/gems/mysql2-0.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:314:in `execute'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:383:in `send'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:383:in `method_missing'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:359:in `say_with_time'
 /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:359:in `say_with_time'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:379:in `method_missing'
 /home/sean/project/db/migrate/20110324194开发者_高级运维138_geo_data.rb:19:in `up_without_benchmarks'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:312:in `send'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:312:in `migrate'
 /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:312:in `migrate'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:395:in `__send__'
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:395:in `migrate'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:537:in `migrate'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:613:in `call'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:613:in `ddl_transaction'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:536:in `migrate'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:523:in `each'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:523:in `migrate'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:433:in `up'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/migration.rb:415:in `migrate'
 /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/railties/databases.rake:142
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
 /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
 /usr/bin/rake:19:in `load'
 /usr/bin/rake:19


Change LOAD DATA INFILE... to LOAD DATA LOCAL INFILE..

0

精彩评论

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