【问题标题】:Heroku build error: Specified 'sqlite3' for database adapter, but the gem is not loadedHeroku 构建错误:为数据库适配器指定了“sqlite3”,但未加载 gem
【发布时间】:2019-02-08 09:43:24
【问题描述】:

我想要做什么

我正在使用 rails 构建一个应用程序,并将一个非 master 分支部署到 heroku master 测试生产中的应用程序。在我知道我在 Heroku 上做什么之前,我不想和 master 搞混,因此我部署了一个特性分支。

应用程序库can be found here(如果需要引用)。

gemfile 进行任何更改后,我运行:

bundle update
bundle install
git add .
git commit
git push heroku 0007/heroku:master

最后一个命令记录在 here 中,用于将非 master 分支推送到 herokus master。通常这样做是因为你不想惹主人。不久前我也问过这个问题。The question how to set non-master up for heroku can be found here

我调整了 database.yml 以适应 Heroku 对 postgresql 和 sqlite3 的要求。

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

我的 gemfile 也很直接:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

ruby '2.4.1'

# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: :development # Added development group.
gem 'pg', group: :production # Added postgres and made it production only.
gem 'rails_12factor'

# Specifying an exact Ruby version
ruby '2.4.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Step-by-step debugging and stack navigation in Pry
  gem 'pry-byebug', platform: :ruby
  # Pry is a powerful alternative to the standard IRB shell for Ruby
  gem 'pry-rails'
  # Pretty print your Ruby objects with style -- in full color and with proper indentation
  gem 'awesome_print'
  # Add a comment summarizing the current schema to the top or bottom of each of your ActiveRecord models, Specs, factory_girl factories...
  gem 'annotate'
  # Annotate guard runs the annotate gem when needed
  gem 'guard-annotate', '~> 2.3'
  # Use for fighting the N+1 problem in Ruby
  gem 'bullet'
  # Speedup RSpec + Cucumber by running parallel on multiple CPU cores
  gem 'parallel_tests'
  # 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 :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  # bundler-audit provides patch-level verification for Bundled apps
  gem 'bundler-audit', '~> 0.6.0', require: false
  # Bundler guard allows to automatically & intelligently install/update bundle when needed.
  gem 'guard-bundler', '~> 2.1', require: false
  # compare licenses against a user-defined whitelist, and give you an actionable exception report
  gem 'license_finder', '~> 3.0', '>= 3.0.1', require: false
  # Brakeman is an open source static analysis tool which checks Rails applications for security vulnerabilities.
  gem 'brakeman', require: false
  # Better Errors replaces the standard Rails error page with a much better and more useful error page
  gem 'better_errors'
  # necessary to use Better Errors' advanced features
  gem 'binding_of_caller', platforms: :ruby
  # RuboCop configuration which has the same code style checking as official Ruby on Rails
  gem 'rubocop', '~> 0.51.0', require: false
  gem 'guard-rubocop', require: false
  # i18n-tasks helps you find and manage missing and unused translations
  gem 'i18n-tasks', require: false
  # IYE makes it easy to translate your Rails I18N files and keeps them up to date
  gem 'iye', require: false
  # Image Uploader Carrierwave for all kinds of Picture related jobs
  gem 'carrierwave', '~> 1.0'



end

group :test do
  # Guard is a command line tool to easily handle events on file system modifications
  gem 'guard'
  gem 'guard-minitest'
  # This gem brings back assigns to your controller tests as well as assert_template
  gem 'rails-controller-testing'
  # To get the default Rails tests to show red and green at the appropriate times
  gem 'minitest-reporters'
  # Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing.
  gem 'database_cleaner'
  # Code coverage for Ruby
  gem 'simplecov', require: false
  # Collection of testing matchers extracted from Shoulda
  gem 'shoulda-matchers'
end

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

问题

在本地测试我的应用后,我决定将其推送到 Heroku,但是我无法解决依赖冲突。

疑似错误:

为数据库适配器指定了“sqlite3”,但未加载 gem。 将gem 'sqlite3' 添加到您的 Gemfile

我知道这个问题在很多帖子中都有记录。我梳理了它们以找到我错过的内容,但无济于事。

这些是我在这个问题上找到的帖子:

他们基本上都说,注意您将 postgresql 设置为生产数据库,将 sqlite3 设置为开发数据库,​​或者从一开始就使用 postgres 设置您的项目。

据我所知,我已经涵盖了这一点。

我将我的 gemfile 设置为使用 pg 作为生产数据库,使用 sqlite3 作为开发数据库,​​如上所述 herehere

我的 gemfile 似乎没有任何用于 sqlite 的生产部门。

 [57] → gem dependency -R sqlite
Gem sqlite3-1.3.13
  hoe (~> 3.15, development)
  hoe-bundler (~> 1.0, development)
  mini_portile (~> 0.6.2, development)
  minitest (~> 5.9, development)
  rake-compiler (~> 0.9.3, development)
  rake-compiler-dock (~> 0.5.2, development)
  rdoc (~> 4.0, development)
  Used by
    awesome_print-1.8.0 (sqlite3 (>= 0, development))
    database_cleaner-1.7.0 (sqlite3 (>= 0, development))
    rails-controller-testing-1.0.2 (sqlite3 (>= 0, development))
    sass-rails-5.0.7 (sqlite3 (>= 0, development))

在尝试运行 $ heroku run rake db:migrate 时开始出现问题。

这是heroku制作的足迹:

 [159] → heroku logs --tail
2018-09-03T03:00:29.276401+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `tap'
2018-09-03T03:00:29.276425+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `perform'
2018-09-03T03:00:29.276472+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
2018-09-03T03:00:29.276495+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
2018-09-03T03:00:29.276518+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform'
2018-09-03T03:00:29.276542+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke'
2018-09-03T03:00:29.276567+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands.rb:16:in `<top (required)>'
2018-09-03T03:00:29.276591+00:00 app[web.1]: from bin/rails:9:in `require'
2018-09-03T03:00:29.276615+00:00 app[web.1]: from bin/rails:9:in `<main>'
2018-09-03T08:35:36.524552+00:00 heroku[web.1]: State changed from crashed to starting
2018-09-03T08:35:39.232773+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 52942 -e production`
2018-09-03T08:35:42.729326+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-03T08:35:42.656882+00:00 app[web.1]: => Booting Puma
2018-09-03T08:35:42.656898+00:00 app[web.1]: => Rails 5.1.6 application starting in production
2018-09-03T08:35:42.656899+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-09-03T08:35:42.656900+00:00 app[web.1]: Exiting
2018-09-03T08:35:42.656943+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/connection_specification.rb:188:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
2018-09-03T08:35:42.656967+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/connection_specification.rb:185:in `spec'
2018-09-03T08:35:42.656977+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:880:in `establish_connection'
2018-09-03T08:35:42.656980+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/connection_handling.rb:58:in `establish_connection'
2018-09-03T08:35:42.656982+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/railtie.rb:124:in `block (2 levels) in <class:Railtie>'
2018-09-03T08:35:42.656983+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval'
2018-09-03T08:35:42.657020+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
2018-09-03T08:35:42.657023+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
2018-09-03T08:35:42.657024+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
2018-09-03T08:35:42.657027+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
2018-09-03T08:35:42.657038+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:49:in `each'
2018-09-03T08:35:42.657065+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
2018-09-03T08:35:42.657068+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/base.rb:326:in `<module:ActiveRecord>'
2018-09-03T08:35:42.657070+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/base.rb:25:in `<top (required)>'
2018-09-03T08:35:42.657073+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
2018-09-03T08:35:42.657083+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require'
2018-09-03T08:35:42.657086+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency'
2018-09-03T08:35:42.657110+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
2018-09-03T08:35:42.657113+00:00 app[web.1]: from /app/app/models/application_record.rb:1:in `<top (required)>'
2018-09-03T08:35:42.657123+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
2018-09-03T08:35:42.657128+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require'
2018-09-03T08:35:42.657152+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency'
2018-09-03T08:35:42.657153+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
2018-09-03T08:35:42.657154+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:379:in `block in require_or_load'
2018-09-03T08:35:42.657178+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:36:in `block in load_interlock'
2018-09-03T08:35:42.657181+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
2018-09-03T08:35:42.657184+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/concurrency/share_lock.rb:149:in `exclusive'
2018-09-03T08:35:42.657186+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies/interlock.rb:11:in `loading'
2018-09-03T08:35:42.657212+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:36:in `load_interlock'
2018-09-03T08:35:42.657213+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:357:in `require_or_load'
2018-09-03T08:35:42.657216+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:335:in `depend_on'
2018-09-03T08:35:42.657220+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:251:in `require_dependency'
2018-09-03T08:35:42.657224+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!'
2018-09-03T08:35:42.657226+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:475:in `each'
2018-09-03T08:35:42.657230+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:475:in `block in eager_load!'
2018-09-03T08:35:42.657232+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:473:in `each'
2018-09-03T08:35:42.657234+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:473:in `eager_load!'
2018-09-03T08:35:42.657238+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:354:in `eager_load!'
2018-09-03T08:35:42.657240+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application/finisher.rb:67:in `each'
2018-09-03T08:35:42.657241+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application/finisher.rb:67:in `block in <module:Finisher>'
2018-09-03T08:35:42.657243+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec'
2018-09-03T08:35:42.657247+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run'
2018-09-03T08:35:42.657249+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers'
2018-09-03T08:35:42.657250+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
2018-09-03T08:35:42.657252+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
2018-09-03T08:35:42.657254+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
2018-09-03T08:35:42.657257+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
2018-09-03T08:35:42.657259+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each'
2018-09-03T08:35:42.657260+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `call'
2018-09-03T08:35:42.657261+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
2018-09-03T08:35:42.657262+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
2018-09-03T08:35:42.657264+00:00 app[web.1]: from /app/vendor/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
2018-09-03T08:35:42.657266+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers'
2018-09-03T08:35:42.657267+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!'
2018-09-03T08:35:42.657268+00:00 app[web.1]: from /app/config/environment.rb:5:in `<top (required)>'
2018-09-03T08:35:42.657270+00:00 app[web.1]: from config.ru:3:in `require_relative'
2018-09-03T08:35:42.657273+00:00 app[web.1]: from config.ru:3:in `block in <main>'
2018-09-03T08:35:42.657274+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:55:in `instance_eval'
2018-09-03T08:35:42.657275+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:55:in `initialize'
2018-09-03T08:35:42.657278+00:00 app[web.1]: from config.ru:in `new'
2018-09-03T08:35:42.657279+00:00 app[web.1]: from config.ru:in `<main>'
2018-09-03T08:35:42.657280+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:49:in `eval'
2018-09-03T08:35:42.657283+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:49:in `new_from_string'
2018-09-03T08:35:42.657284+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/builder.rb:40:in `parse_file'
2018-09-03T08:35:42.657287+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/server.rb:319:in `build_app_and_options_from_config'
2018-09-03T08:35:42.657288+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/server.rb:219:in `app'
2018-09-03T08:35:42.657290+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:24:in `app'
2018-09-03T08:35:42.657291+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/server.rb:354:in `wrapped_app'
2018-09-03T08:35:42.657294+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/server.rb:283:in `start'
2018-09-03T08:35:42.657295+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:44:in `start'
2018-09-03T08:35:42.657301+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:135:in `block in perform'
2018-09-03T08:35:42.657302+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `tap'
2018-09-03T08:35:42.657305+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `perform'
2018-09-03T08:35:42.657306+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
2018-09-03T08:35:42.657307+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
2018-09-03T08:35:42.657308+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
2018-09-03T08:35:42.657311+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform'
2018-09-03T08:35:42.657312+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke'
2018-09-03T08:35:42.657313+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands.rb:16:in `<top (required)>'
2018-09-03T08:35:42.657316+00:00 app[web.1]: from bin/rails:9:in `require'
2018-09-03T08:35:42.657318+00:00 app[web.1]: from bin/rails:9:in `<main>'
2018-09-03T08:35:42.704940+00:00 heroku[web.1]: Process exited with status 1
2018-09-03T09:52:58.423149+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=attendion.herokuapp.com request_id=fc40234e-28c4-4007-a780-1731f87512d4 fwd="87.144.250.234" dyno= connect= service= status=503 bytes= protocol=https
2018-09-03T09:52:59.224100+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=attendion.herokuapp.com request_id=786316ef-6db5-48b9-9590-5467827cf791 fwd="87.144.250.234" dyno= connect= service= status=503 bytes= protocol=https

【问题讨论】:

  • 你需要指定postgresql作为生产适配器
  • AFAIC 我在 gemfile 中使用 gem 'pg', group: :production 进行了此操作。你能设置一个答案来说明我没有做到这一点吗?
  • database.yml
  • 您可以链接来源或详细说明吗?
  • 您可以在您的链接来源之一中找到它

标签: ruby-on-rails heroku rubygems


【解决方案1】:

SQLite 不能与 Heroku 一起使用,因为它是基于磁盘的,而 Heroku 使用临时文件系统。

SQLite 在内存中运行,并将其数据存储备份到磁盘上的文件中。 虽然这种策略非常适合开发,但 Heroku 的 Cedar 堆栈 有一个临时文件系统。你可以写它,你可以读 从它,但内容将定期清除。如果你要 在 Heroku 上使用 SQLite,您至少会丢失整个数据库 每 24 小时一次。

即使 Heroku 的磁盘持久运行 SQLite 仍然不会 很合适。由于 SQLite 不作为服务运行,因此每个 dyno 都会 运行单独的运行副本。这些副本中的每一个都需要自己的磁盘 支持的商店。这意味着为您的应用程序供电的每个测功机都会 由于磁盘未同步,因此具有不同的数据集。

-Heroku Devcenter: SQLite on Heroku

Heroku 提供 Postgres 作为 Rails 的免费默认数据库,这与您所能获得的推荐非常接近。

如果您要部署到 Postgres,您还应该在 Postgres 上进行开发/测试。

支持服务之间的差异意味着微小的不兼容性 突然出现,导致代码在开发中工作并通过测试,或者 分期生产失败。这些类型的错误会产生摩擦 这会抑制持续部署。这种摩擦的代价 并且后续对持续部署的抑制非常 在应用程序的整个生命周期内综合考虑时很高。
- https://12factor.net/dev-prod-parity

如果你真的想坚持使用 SQLite,你需要正确配置适配器:

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  adapter: postgresql
  # nothing else is needed

【讨论】:

  • 我会参考 Heroku 为 properly setting up postgres 提供的详细指南 - 但您目前遇到的错误是由于您使用的是 sqlite 适配器而不是 adapter: postgresql。跨度>
猜你喜欢
  • 1970-01-01
  • 2014-08-11
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
  • 1970-01-01
  • 1970-01-01
  • 2015-12-26
  • 2023-03-17
相关资源
最近更新 更多