来自heroku的数据库因Encoding :: CompatibilityError而失败 [英] DB pull from heroku fails with Encoding::CompatibilityError

查看:118
本文介绍了来自heroku的数据库因Encoding :: CompatibilityError而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的设置是从MacPorts的MySQL(5.1.50)中执行db:从heroku拉回到我的本地开发环境。通过RVM在Mac OS X Snow Leopard上安装在本地Rails 3 / Ruby 1.9.2环境中,并且已成功执行 heroku db:push 到生产站点Heroku很多次。但是,在具有相同设置的二级开发机器上,当我尝试通过 heroku db:pull 将Heroku DB拉回时,在下载完成后出现以下错误表格和索引信息:

  /Users/jschuur/.rvm/gems/ruby-1.9.2-p0 /gems/sequel-3.15.0/lib/sequel/adapters/shared/mysql.rb:399:in`join':不兼容的字符编码:UTF-8和ASCII-8BIT(Encoding :: CompatibilityError)
from /Users/jschuur/.rvm/gems/ruby-1.9.2-p0/gems/sequel-3.15.0/lib/sequel/adapters/shared/mysql.rb:399:in`multi_insert_sql'

以下是相关的宝石:

  ruby​​-mysql(2.9.3)
sequel(3.15.0)
mysql2(0.2.4)
点击(0.3.13)
heroku(1.10.6, 1.10.5,1.10.0)

完整的错误和宝石列表 here

同样的错误发生在我的主生产机器上BTW(我一直在做成功的db:push到heroku的形式)。

现在我明白这基本上是一个UTF8编码错误。 FWIW,我的database.yml明确地引用了UTF8:

 开发:
适配器:mysql2
编码:utf8
database:rails_dev_dbname
pool:5
username:rails $ b $ socket:/tmp/mysql.sock

现在有趣的是,如果我创建一个几乎空白的数据库,并且只有一个测试条目,我可以推/拉它。所以很明显,在我的非UTF8数据集中。尽管这里没有太多的数据,但我完全有可能复制一些包含时髦引用或版权符号的文字,使其窒息。

所以问题是,我如何解决这个问题? Heroku文档在推送时提及在数据库URL中附加'?encoding = utf',但我假设我的默认 heroku db:push 将数据发送给Heroku,首先使用 database.yml ,已经有了这一套。无论哪种方式,我这样做了一个明确的推动,后续拉仍然有同样的问题。

解决方案

我切换我的红宝石版本为1.8.7,当使用水龙头推拉时,当我得到错误,所以你可能想试试。



如果你不使用这个已经使用 RVM 来管理您的Ruby版本


I'm having some problems performing a db:pull from heroku back to my local development enviroment.

My setup is MySQL (5.1.50) from a MacPorts install on a local Rails 3/Ruby 1.9.2 environment under Mac OS X Snow Leopard via RVM, and I've successfully performed a heroku db:push to the production site on Heroku many times. However, on a secondary development machine with the same setup, when I try and pull the Heroku DB back via heroku db:pull, I get the following error, after it downloads the table and index info for a short while:

/Users/jschuur/.rvm/gems/ruby-1.9.2-p0/gems/sequel-3.15.0/lib/sequel/adapters/shared/mysql.rb:399:in `join': incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError)
    from /Users/jschuur/.rvm/gems/ruby-1.9.2-p0/gems/sequel-3.15.0/lib/sequel/adapters/shared/mysql.rb:399:in `multi_insert_sql'

Here's the relevant gems:

ruby-mysql (2.9.3)
sequel (3.15.0)
mysql2 (0.2.4)
taps (0.3.13)
heroku (1.10.6, 1.10.5, 1.10.0)

Full error and gem list here.

The same error happens on my primary production machine BTW (the one where I've been doing the successful db:push to heroku form).

Now I understand that this is basically a UTF8 encoding error. FWIW, my database.yml explicitly references UTF8:

development:
  adapter: mysql2
  encoding: utf8
  database: rails_dev_dbname
  pool: 5
  username: rails
  socket: /tmp/mysql.sock

Now interestingly, if I create an almost blank DB with just a single test entry in it, I can push/pull it fine. So obviously something in my dataset of non UTF8. While there's not a lot of data there yet, it's entirely possible that I copied some text among it that contains a funky quote or a copyright symbol that it's choking on.

So the question is, how do I get around this problem? The Heroku docs do mention appending '?encoding=utf' to your DB URL when you do a push, but I assume that my default heroku db:push that sent the data to Heroku in the first place used database.yml, which already has that set. Either way, I did an explicit push this way, and a subsequent pull still has the same problem.

解决方案

I switch my ruby version to 1.8.7 when using taps to push and pull when I get errors so you might want to give that a try.

If you don't use this already use RVM to manage your ruby versions

这篇关于来自heroku的数据库因Encoding :: CompatibilityError而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆