從mysql插入數據到postgres時出現以下錯誤。Postgres插入錯誤 - PG ::錯誤:錯誤:無效的字節序列編碼「UTF8」:0xe073
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在我PG數據庫rake任務
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
你用什麼來插入數據,你試圖插入什麼字符? –
(正確的說0xe073在UTF-8中是一個無效的字節序列,儘管...) –
我更新了我的問題 – nadine1988