rake db:迁移中止!在 US-ASCII 上使用 rake 0.9.2.2 和rails 3.0.10

发布于 2024-12-24 02:53:01 字数 557 浏览 2 评论 0原文

最近,我升级了 gems,并开始向我的应用程序添加新内容,例如第三方社交网站使用omniauth gem 进行身份验证。在开发环境上一切都很好并且工作起来很有魅力。

我正在使用 capistrano 部署到临时和生产服务器。到目前为止,基本部署很好并且工作正常,但是当我想在部署时进行迁移时,我遇到了非常奇怪的问题。

我从 capistrano 收到以下错误消息:

    [my.server.com] executing command
*** [err :: my.server.com] rake aborted!
*** [err :: my.server.com] "\xC5" on US-ASCII
*** [err :: my.server.com] 
*** [err :: my.server.com] (See full trace by running task with --trace)
    command finished in 2472ms

我到处搜索,找不到任何相关的解决方案。我还尝试将 rake gem 降级回 0.8.7,但最终没有成功 - 同样的错误。

Recently I upgraded my gems and started adding new stuff to my app like authentication by third party social websites using omniauth gem. On development environment everything is fine and works like a charm.

I am deploying to staging and production servers using capistrano. Basic deployment is fine and working so far, but I have got really strange problems when I want to do migrations when deploying.

I get the following error messages from capistrano:

    [my.server.com] executing command
*** [err :: my.server.com] rake aborted!
*** [err :: my.server.com] "\xC5" on US-ASCII
*** [err :: my.server.com] 
*** [err :: my.server.com] (See full trace by running task with --trace)
    command finished in 2472ms

I was googling all around and couldn't find any relevant solution. I also tried to downgrade rake gem back to 0.8.7 but with no success on the end - the same errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷了相思 2024-12-31 02:53:01

经过几个小时的谷歌搜索和挖掘后,我找到了(我希望)可能对遇到类似或相同问题的人有所帮助的解决方案。

我在临时服务器上执行了 bundle exec rake --trace db:migrate 并收到以下错误消息:

rake aborted!
"\xC5" on US-ASCII
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `read'
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `<top (required)>'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `require'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `<main>'

因此我跳入 config/application.rb 文件查找找出什么可能会导致错误。该文件的第 5 行加载一个外部配置文件:

require 'yaml'
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))

并且该外部文件包含 UTF-8 字符,而不是 US-ASCII。所以我尝试了几种不同的解决方案来解决这个问题。

唯一对我有用的是在 config/application.rb 文件顶部添加额外的几行代码:

if RUBY_VERSION =~ /1.9/
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8
end

只是告诉 rake 使用 utf-8 编码加载外部文件。在那次改变之后,一切都很顺利并且完全符合预期。问题解决了!

PS.
我真的不知道为什么 rake 0.9 的开发者改变了 rake 0.8 以前的行为,这对我来说工作得很好,可能对你来说也很长一段时间。也许你知道为什么?我很好奇。

After hours of googling and digging in I found the solution that (I hope) may by helpful for someone with a similar or the same problem.

I did bundle exec rake --trace db:migrate on the staging server and got the following error messages:

rake aborted!
"\xC5" on US-ASCII
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `read'
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `<top (required)>'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `require'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `<main>'

So I jumped in to the config/application.rb file to find out what could rise the error. Line 5 of that file loads an external config file:

require 'yaml'
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))

and that external file contains UTF-8 chars, not US-ASCII. So I tried a couple of different solutions to solve that problem.

The only one which worked for me was to add an extra few lines of code on top of config/application.rb file:

if RUBY_VERSION =~ /1.9/
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8
end

just to tell rake to load external files using utf-8 encoding. After that change everything went smooth and exactly as expected. Problem solved!

PS.
I really don't know why developers of rake 0.9 have changed previous behavior of rake 0.8 which worked fine for me and probably for you as well for a long time. Maybe you have an idea why? I am very curious.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文