2

我正在使用 Rails 3.2.6 尝试运行

heroku run rake db:migrate

我得到适配器错误

rake aborted!
Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.)

在我的database.yml中,我有开发、生产和测试集:

adapter: mysql2

这是我的宝石环境

➜  my_app git:(master) gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.24
  - RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-darwin11.4.2]
  - INSTALLATION DIRECTORY: /Users/jcollyer/.rvm/gems/ruby-1.9.3-p327
  - RUBY EXECUTABLE: /Users/jcollyer/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/jcollyer/.rvm/gems/ruby-1.9.3-p327/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/jcollyer/.rvm/gems/ruby-1.9.3-p327
     - /Users/jcollyer/.rvm/gems/ruby-1.9.3-p327@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

我尝试了一些我发现谷歌搜索的东西,没有运气。任何帮助表示赞赏!谢谢!

4

2 回答 2

7

Remember that Heroku uses the config property DATABASE_URL instead of your database.yml file for connecting to your db. Make sure it is set. If you are using the ClearDB add-on, then the value you want should be in the CLEARDB_DATABASE_URL.

heroku config

Copy the value that ClearDB will have set for you in the CLEARDB_DATABASE_URL config variable. Set the DATABASE_URL to the same value

heroku config:set DATABASE_URL=mysql2://bb06ca765fb123:71b6dabc@us-cdbr-east-04.cleardb.com/heroku_703eded6aebc123?reconnect=true

Here's the catch. Most people are using the mysql2 gem, so you typically need to set the DATABASE_URL to mysql2... instead of mysql.

There's no need to abandon mysql and migrate to postgre.

于 2013-07-23T16:24:04.727 回答
1

在 Heroku 上,您最好的数据库选择是 postgresql,毫无疑问。有几个原因可以归结为:Heroku 就是这样设计的。

如果您只是使用 rails orm,您可以在开发环境中使用 mysql2psql gem,并更改配置文件以在生产中使用 postgresql。

如果你因为某种原因真的嫁给了 mysql,你需要安装一个 heroku 插件来让你的应用程序启动并运行。有几个选项,但这里有一个:https ://addons.heroku.com/cleardb

但实际上,您最好的选择是将您的应用程序迁移到 postgresql,这是值得的。

更多信息: https ://devcenter.heroku.com/articles/heroku-mysql

于 2013-05-10T16:03:10.270 回答