将数据从 mysql 插入 postgres 时出现以下错误。
PG::Error: ERROR: invalid byte sequence for encoding "UTF8": 0xe073
: INSERT INTO "places" ("accent_city", "city", "country", "created_at", "latitude", "longitude", "region", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"
我想将此文件worldcitiespop.txt作为 rake 任务插入到我的 PG 数据库中
namespace :places_db do
desc "save cities in database"
task save_places: :environment do
File.open("lib/city_name/worldcitiespop.txt", "r").each_line do |row|
row = row.force_encoding('ISO-8859-1').split(',')
Place.create(country: row[0], city: row[1], accent_city: row[2], region: row[3], latitude: row[5], longitude: row[6])
end
end
end