Rails 3.2从SQLite本地到Herg的Postgres

时间:2012-04-16 17:56:00

标签: ruby-on-rails sqlite postgresql heroku

我在本地使用sqlite开发应用程序,但现在想将它移动到Heroku,所以我将从现在开始使用postgres。到目前为止我不需要保留数据库,我只需要Heroku不要尝试安装Sqlite,因为它会像这样爆炸:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
       /usr/local/bin/ruby extconf.rb
       checking for sqlite3.h... no
       sqlite3.h is missing. Try 'port install sqlite3 +universal'
       or 'yum install sqlite-devel' and check your shared library search path (the
       location where your sqlite3 shared library is located).
       *** extconf.rb failed ***
       Could not create Makefile due to some reason, probably lack of
       necessary libraries and/or headers.  Check the mkmf.log file for more
       details.  You may need configuration options.

我已经更改了我的database.yml文件,并在我的Gemfile中将'gem' "sqlite3"切换为'gem' "pg",但是heroku仍然很生气。还有什么需要改变,所以当我提交我的应用程序时它不会尝试安装sqlite3?

1 个答案:

答案 0 :(得分:4)

一旦你改变你的Gemfile以使用gem'pg',你需要重新运行bundle命令。完成后,将Gemfile和Gemfile.lock提交到git,然后将应用程序推送到Heroku,它应该可以正常工作。

如果您没有在本地运行Postgres,那么您应该在Gemfile中向生产组添加gem'pg',否则当您在本地运行bundle时,在尝试编译gem时会遇到问题。您可以安全地将gem'sqlite'移动到Gemfile中的开发组,以在环境之间使用不同的DB。 警告说,在部署时,最安全的是在本地运行相同的数据库。