如何从SQLite3切换到Postgres以在Heroku上部署

时间:2016-09-30 11:39:00

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

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

这是我的宝石文件:

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)

1 个答案:

答案 0 :(得分:0)

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

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

并将您的sqlite3 gem转移到

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

运行bundle install --without production你应该好好去