无法将 Rails 应用程序部署到 Heroku;当我不使用任何数据库时抱怨 postgres

Can't deploy Rails app to Heroku; complains about postgres when I'm not using any DB

我已经构建了我的第一个 rails 应用程序,我正在尝试将它部署到 Heroku,但每次我推送时应用程序都会崩溃。当我尝试登录 rails 控制台时,看到的是:

Running rails console attached to terminal... up, run.6183 /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:177:in rescue in spec': Specified 'postgresql' for database adapter, but the gem is not loaded. Addgem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

我什至没有在我的应用程序中使用任何数据库。 这是我的 database.yml 文件的样子:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#

development:

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:

production:

有人可以帮我吗?

谢谢!

我相信 heroku 使用它自己的自动数据库配置而忽略了你的 database.yml 这解释了为什么它仍然需要 postgres。除了包含 gem.

之外,我不确定你能做些什么

您可以在 gem 文件中执行此操作。

group :production do
  gem 'rails_12factor'
end

问题是 heroku 将重写 database.yml 或设置 rails 将自动获取的环境变量。

您需要实际停止 Activerecord 加载:

为此,您需要替换 config/application.rb

顶部的 require "rails/all"

require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"

您还需要删除 config/initializers 或 config/environments 中引用 activerecord

的所有内容