2015-12-19 1 views
1

Sur le jeu de caractères de MySQL "utf8mb4",
la console rails fonctionne bien comme ça.
Sur le jeu de caractères de MySQL "utf8mb4", même la console rails fonctionne bien, mais seed_fu ne fonctionne pas bien

<pre> 
<p style="background-color:#FFFFFF;border:1px solid #999999;padding:5px;"> 
10191% rails c -e production                                 Loading production environment (Rails 4.2.5) 
irb(main):001:0> skin = Skin.first 
    Skin Load (203.9ms) SELECT `skins`.* FROM `skins` ORDER BY `skins`.`id` ASC LIMIT 1 
=> #<Skin id: 1, created_at: "2015-12-19 07:59:48", updated_at: "2015-12-19 08:08:34", name: "", file: "standard.css", expression: ""> 
irb(main):002:0> skin.name = 'たのしい'' 
irb(main):003:0' 
irb(main):004:0' ' 
=> "たのしい\n\n" 
irb(main):005:0> skin.name = 'たのしい' 
=> "たのしい" 
irb(main):006:0> skin.save 
    (112.3ms) BEGIN 
    SQL (115.0ms) UPDATE `skins` SET `name` = 'たのしい', `updated_at` = '2015-12-19 11:56:18' WHERE `skins`.`id` = 1 
    (105.7ms) COMMIT 
=> true 
</p> 
</pre> 


Mais "rake db: seed_fu" ne court pas bien comme ça.

<pre> 
<p style="background-color:#FFFFFF;border:1px solid #999999;padding:5px;"> 
10192% rake db:seed_fu RAILS_ENV=production 
== Seed from /Users/js/work/picrating/db/fixtures/production/publish.rb 
- Publish {:id=>1, :name=>"公開"} 
- Publish {:id=>2, :name=>"非公開"} 

== Seed from /Users/js/work/picrating/db/fixtures/production/skin.rb 
- Skin {:id=>1, :name=>"standard", :file=>"standard.css", :expression=>"レギュラー"} 
- Skin {:id=>2, :name=>"light", :file=>"light.css", :expression=>"たのしい"} 
rake aborted! 
ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect string value: '\xF0\x9F\x8C\xBB' for column 'expression' at row 1: INSERT INTO `skins` (`id`, `name`, `file`, `expression`, `created_at`, `updated_at`) VALUES (2, 'light', 'light.css', 'たのしい', '2015-12-19 12:08:05', '2015-12-19 12:08:05') 
(eval):1:in `block (2 levels) in run_file' 
Mysql2::Error: Incorrect string value: '\xF0\x9F\x8C\xBB' for column 'expression' at row 1 
(eval):1:in `block (2 levels) in run_file' 
Tasks: TOP => db:seed_fu 
(See full trace by running task with --trace) 

</p> 
</pre> 


Je ne sais pas, que des rails même console fonctionne bien, mais
db: seed_fu ne fonctionne pas très bien.
Que s'est-il passé?

+0

Tout indique qu'il est configuré pour UTF8, non utf8mb4. –

Répondre

0

Est-ce une indication suffisante?

Dans application_controller.rb

def configure_charsets 
    response.headers["Content-Type"] = "text/html; charset=utf-8" 
    suppress(ActiveRecord::StatementInvalid) do 
     ActiveRecord::Base.connection.execute 'SET NAMES utf8mb4' 
    end 
    end