“\xC4” from ASCII-8BIT to UTF-8 when running rake db:migrate on Heroku

三世轮回 提交于 2019-12-24 09:28:23

问题


When I try to run heroku run rake db:migrate in my application, I get the following error

"\xC4" from ASCII-8BIT to UTF-8

with a stacktrace of

/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `write'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `puts'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `display_error_message'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:142:in `rescue in standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:132:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `load'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `'

I've tried setting encoding manually in config/environment.rb via

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

But it doesn't seem to help. The problem might be, that I'm using slim as a templating engine with many unicode characters directly in the templates, but I'm not sure if there's a better way of doing that.


回答1:


Simply add this to the top of your file

# encoding: UTF-8

this error is frequent with migration when you insert data. For exemple I've got this with a simple migration adding Québec

Province.create(:name => 'Québec (Canada)')


来源:https://stackoverflow.com/questions/8797469/xc4-from-ascii-8bit-to-utf-8-when-running-rake-dbmigrate-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!