【问题标题】:Heroku with rails 5 error Gem::LoadError: Specified 'postgresql' for database adapterHeroku with rails 5 error Gem::LoadError: Specified 'postgresql' for database adapter
【发布时间】:2018-06-24 04:31:49
【问题描述】:

我是 Rails 初学者,在部署到 Heroku 时遇到了一些问题。

早些时候我使用 SQLite3,后来当我了解到我需要 postgresql 时,我安装了相同的并在本地机器上工作。

从 sqlite 迁移到 postgresql 后,一次部署运行良好。现在我看到了一些问题。

Heroku 日志、Gem 文件和 Database.yml 详细信息如下。

请有人帮助我。

提前谢谢...!!!

部分 Gem 文件:

group :development, :test do
    gem 'pg', '~> 1.0.0'
  gem 'rails_12factor'
  #gem 'sqlite3'
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
end

group :production do
    gem 'pg', '~> 1.0.0'
  gem 'rails_12factor'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

数据库.yml:

development:
    adapter: postgresql
    encoding: unicode
    database: database_postgresql
    pool: 5
    username: postgres
    password: secret

test:
   adapter: postgresql
    encoding: unicode
    database: database_postgresql_test
    pool: 5
    username: postgres
    password: secret

production:
   adapter: postgresql
    encoding: unicode
    database: database_postgresql
    pool: 5
    username: postgres
    password: secret

Heroku 日志的一部分。

remote: -----> Installing node-v6.11.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        Yarn executable was not detected in the system.
remote:        Download Yarn at https://yarnpkg.com/en/docs/install
remote:        I, [2018-01-15T13:38:08.180450 #590]  INFO -- : Writing /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/public/assets/jumbotron--032aba6cd1415006731040523573e7138c703aedc6d1f46b3622cbe4c9feec27.jpg
remote:        rake aborted!
remote:        Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
remote:        /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:188:in `rescue in spec'

remote:        /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
remote:        /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
remote:        Tasks: TOP => assets:precompile
remote:        (See full trace by running task with --trace)
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to damp-beyond-28813.

【问题讨论】:

    标签: ruby-on-rails heroku deployment ruby-on-rails-5


    【解决方案1】:

    如果您最近将您的应用程序部署到 Heroku,并且在您尝试访问 Heroku 应用程序链接时遇到“应用程序崩溃”错误,但其他一切似乎都正常,这很可能是由于新的发布'pg' gem。 Postgres 发布了一个新版本的 gem,它似乎还不完全兼容,所以在 group production 下的 Gemfile 中更改行:

    gem 'pg'
    OR
    gem 'pg', '~> 1.0.0'
    

    gem 'pg', '~> 0.11'
    OR
    gem 'pg', '~> 0.20.0'
    

    注意:&gt; 之前的波浪号,这不是破折号

    在您的 Gemfile 的小组生产中进行此更新后,请确保您运行 bundle install --without production(以更新 Gemfile.lock 文件),执行 git add/commit 循环,然后重新部署到 Heroku。

    为了良好实践

    使用pg gem 一次而不使用:group,因为developmentproduction! 的数据库相同

    【讨论】:

    • 感谢 @fool-dev 解决问题。你又救了我……现在我看到remote: Stock Load (1.2ms) SELECT "stocks".* FROM "stocks" remote: rake aborted! remote: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "stocks" does not exist remote: LINE 1: SELECT "stocks".* FROM "stocks" remote: ^ remote: : SELECT "stocks".* FROM "stocks"我已经重置了我的数据库,这仍然让我很困扰。
    • Heroku 也已使用这个新架构迁移。
    • @AbdulMuqeem 查看文档以获取配置 Heroku postgress 凭证devcenter.heroku.com/articles/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 2014-05-21
    相关资源
    最近更新 更多