【问题标题】:Rails 3.2 from SQLite locally to Postgres on Heroku从本地 SQLite 到 Heroku 上的 Postgres 的 Rails 3.2
【发布时间】:2012-04-28 01:52:41
【问题描述】:

我在本地使用 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?

【问题讨论】:

    标签: ruby-on-rails sqlite postgresql heroku


    【解决方案1】:

    将 Gemfile 更改为使用 gem 'pg' 后,您需要重新运行 bundle 命令。完成后,将 Gemfile 和 Gemfile.lock 提交到 git,然后将应用程序推送到 Heroku,它应该可以工作了。

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

    【讨论】:

    • 我运行 bundle,它显示了我所有的 gem(pg,但不是 sqlite),然后当我提交同样的错误时
    • 当你提交你得到一个 sqlite 错误?捆绑后确保执行git add Gemfile Gemfile.lock,然后提交,然后执行git push heroku
    • 已修复。我已经将部署版本分支到“heroku”,所以当我执行git push heroku heroku 时,它假设heroku 上有一个heroku 分支(当我想推送到master 时。)所以git push heroku heroku:master 修复了它。
    • 酷——如果你在一个非主分支工作,那将是我的下一个问题。很高兴你把它整理好了。
    猜你喜欢
    • 2014-07-21
    • 1970-01-01
    • 2012-04-13
    • 2013-08-03
    • 2011-09-08
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    • 2013-10-19
    相关资源
    最近更新 更多