【问题标题】:How to switch from SQLite3 to Postgres to deploy on Heroku如何从 SQLite3 切换到 Postgres 以在 Heroku 上部署
【发布时间】:2017-02-08 23:35:01
【问题描述】:

我的初始数据库是 SQLite 3,但 heroku 不支持它,我必须切换到 PostgreSQL。我尝试在 gemfile 中添加 gem,但部署仍然失败。

这是我的 gemfile:

source 'https://rubygems.org'
  gem 'postgres', '~> 0.8.1'
group :development, :test do
  gem 'sqlite3'
end

部署日志中的这段摘录显示了失败的原因:

...

Bundled gems are installed into ./vendor/bundle.
remote:        Post-install message from rdoc:
remote:        Depending on your version of ruby, you may need to install ruby rdoc/ri data:
remote:        <= 1.8.6 : unsupported
remote:        = 1.8.7 : gem install rdoc-data; rdoc-data --install
remote:        = 1.9.1 : gem install rdoc-data; rdoc-data --install
remote:        >= 1.9.2 : nothing to do! Yay!
remote:        Post-install message from haml:
remote:        HEADS UP! Haml 4.0 has many improvements, but also has changes that may break
remote:        your application:
remote:        * Support for Ruby 1.8.6 dropped
remote:        * Support for Rails 2 dropped
remote:        * Sass filter now always outputs <style> tags
remote:        * Data attributes are now hyphenated, not underscored
remote:        * html2haml utility moved to the html2haml gem
remote:        * Textile and Maruku filters moved to the haml-contrib gem
remote:        For more info see:
remote:        http://rubydoc.info/github/haml/haml/file/CHANGELOG.md
remote:        Post-install message from compass:
remote:        Compass is charityware. If you love it, please donate on our behalf at http://umdf.org/compass Thanks!
remote:        Post-install message from postgres:
remote:        ---------------------------------------------------------------------------
remote:        This is an old, deprecated version of the Ruby PostgreSQL driver that hasn't
remote:        been maintained or supported since early 2008.
remote:        You should install/require 'pg' instead.
remote:        If you need the 'postgres' gem for legacy code that can't be converted, you can
remote:        still install it using an explicit version, like so:
remote:        gem install postgres -v '0.7.9.2008.01.28'
remote:        gem uninstall postgres -v '>0.7.9.2008.01.28'
remote:        If you have any questions, the nice folks in the Google group can help:
remote:        ---------------------------------------------------------------------------
remote:        Post-install message from paperclip:
remote:        ##################################################
remote:        #  NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER       #
remote:        ##################################################
remote:        Paperclip is now compatible with aws-sdk >= 2.0.0.
remote:        If you are using S3 storage, aws-sdk >= 2.0.0 requires you to make a few small
remote:        changes:
remote:        * You must set the `s3_region`
remote:        * If you are explicitly setting permissions anywhere, such as in an initializer,
remote:        note that the format of the permissions changed from using an underscore to
remote:        using a hyphen. For example, `:public_read` needs to be changed to
remote:        `public-read`.
remote:        For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
remote:        http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
remote:        Post-install message from twitter-bootstrap-rails:
remote:        Important: You may need to add a javascript runtime to your Gemfile in order for bootstrap's LESS files to compile to CSS.
remote:        **********************************************
remote:        ExecJS supports these runtimes:
remote:        therubyracer - Google V8 embedded within Ruby
remote:        therubyrhino - Mozilla Rhino embedded within JRuby
remote:        Node.js
remote:        Apple JavaScriptCore - Included with Mac OS X
remote:        Microsoft Windows Script Host (JScript)
remote:        **********************************************
remote:        Bundle completed (47.33s)
remote:        Cleaning up the bundler cache.
remote: sh: 1: $: not found
remote: sh: 1: $: not found
remote:  !
remote:  !     Could not detect rake tasks
remote:  !     ensure you can run `$ bundle exec rake -P` against your app
remote:  !     and using the production group of your Gemfile.
remote:  !     This is an old, deprecated version of the Ruby PostgreSQL driver that hasn't
remote:  !     been maintained or supported since early 2008.
remote:  !     
remote:  !     You should install/require 'pg' instead.
remote:  !     
remote:  !     If you need the 'postgres' gem for legacy code that can't be converted, you can
remote:  !     still install it using an explicit version, like so:
remote:  !     
remote:  !     gem install postgres -v '0.7.9.2008.01.28'
remote:  !     gem uninstall postgres -v '>0.7.9.2008.01.28'
remote:  !     
remote:  !     If you have any questions, the nice folks in the Google group can help:
remote:  !     
remote:  !
remote: /app/tmp/buildpacks/f6d48d8a14fccbb19c0c0402fca224929d18e9ee042b3e204bc5992612e990d3b3a0fb1f9627b1a3bae11e9fa20dffc96e136bd734a2f3cf92a0d05bedd42cfe/lib/language_pack/helpers/rake_runner.rb:102:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
remote: ensure you can run `$ bundle exec rake -P` against your app
remote: and using the production group of your Gemfile.
remote: This is an old, deprecated version of the Ruby PostgreSQL driver that hasn't
remote: been maintained or supported since early 2008.
remote: 
remote: You should install/require 'pg' instead.
remote: 
remote: If you need the 'postgres' gem for legacy code that can't be converted, you can
remote: still install it using an explicit version, like so:
remote: 
remote:   gem install postgres -v '0.7.9.2008.01.28'
remote:   gem uninstall postgres -v '>0.7.9.2008.01.28'

...

remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to git_name_repo.
remote: 
To https://git.heroku.com/git_name_repo.git
 ! [remote rejected] master -> master (pre-receive hook declined)

【问题讨论】:

  • 只需在 Gemfile 中写入 production 块并将 pg gem 放入其中
  • 你看输出了吗? 这是 Ruby PostgreSQL 驱动程序的旧版本,已弃用,自 2008 年初以来就没有得到维护或支持。您应该安装/需要“pg”。跨度>
  • 是的,我看到了。但是 you should install/require 'pg' 是什么意思呢?我必须运行什么命令?
  • gem 'pg', '~&gt; 0.19.0' 在 Gemfile 中
  • 欢迎来到 Stack Overflow。请在语法和拼写上投入更多精力。 Stack Overflow 是一本参考书,而不是讨论区,语法和拼写很重要。我们并不期望完美,特别是对于那些母语不是英语但请利用拼写检查器的人。

标签: ruby-on-rails ruby postgresql heroku sqlite


【解决方案1】:

只需在您的 Gemfile 中执行此操作

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

并将您的 sqlite3 gem 转移到

group :development, :test do
  gem 'sqlite3'
end

运行bundle install --without production,你应该很高兴

【讨论】:

  • 还是失败了。使用相同的失败日志。即便如此,你写的也是如此
  • @Orsay 只是为了清楚您在尝试 git push heroku master 时会遇到错误?
  • 是的。对不起,我没有指定
  • 终于成功了。进行更改后,我只是忘记添加和推送我的 git 存储库。非常感谢
猜你喜欢
  • 2021-04-20
  • 1970-01-01
  • 2019-04-23
  • 1970-01-01
  • 2016-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-16
相关资源
最近更新 更多