我是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]
database.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.
答案 0 :(得分:4)
如果你最近将你的应用程序部署到了Heroku,并且你的尝试已经让#34; App崩溃了#34;当您转到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'
注意: >
之前的波浪符号,这不是短划线
在Gemfile的组生产中进行此更新后,请确保运行bundle install --without production
(更新Gemfile.lock文件),执行git add / commit循环,然后重新部署到Heroku。
良好实践
在没有pg gem
的情况下使用:group
一次,因为development
&amp;的数据库相同。 production!