ruby-on-rails - Rails 5.2.3/Heroku - 为什么不能在开发模式下使用 squlite3 在生产模式下运行 postgres?

标签 ruby-on-rails postgresql sqlite heroku

我正在使用 Rails 5.2.3,当我尝试在 Heroku 管道上查看我的生产应用程序时出现应用程序错误,并在以下情况下出现以下错误:

  • 我运行 heroku logs 我得到:heroku[router]: at=error code=H10 desc="App crashed"method=GET path="/"

  • 我运行 heroku run rails console 我得到:加载“sqlite3”Active Record 适配器时出错。缺少它所依赖的 gem ? sqlite3 不是 bundle 的一部分。将它添加到您的 Gemfile 中。 (加载错误)

  • 我运行 heroku run rails db:migrate 我得到:LoadError:加载“sqlite3”Active Record 适配器时出错。缺少它所依赖的 gem ? sqlite3 不是 bundle 的一部分。将它添加到您的 Gemfile。

我想使用 sqlite3 进行开发,使用 postgres 进行生产,那么为什么我需要让 sqlite3 gemfile 在生产模式下可用?

这是我的 gemfile:

group :development do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

这是我的 database.yml:

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

最佳答案

你的问题是这部分:

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

目前您的产品仍在尝试使用 sqlite,因为这会扩展到

production: 
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
  database: db/production.sqlite3

显然 db/production.sqlite3 也建议使用 sqlite 数据库

改为将此部分更改为

production: 
  adapter: postgresql
  host: [your db host] 
  database: [your database] 
  username: [your username]
  password: [your password]
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

话虽如此PostgreSQL是免费的,如果你要部署到 PostgreSQL,你真的不应该再开发 sqlite。

SQLite 非常适合概念验证,因为它可以快速扩展并且易于拆卸,没有真正的外部依赖性,但如果您想真正构建应用程序并将其部署在某个地方,您应该使用生产就绪数据库.

Heroku DB config

Heroku Getting started Rails 5

关于ruby-on-rails - Rails 5.2.3/Heroku - 为什么不能在开发模式下使用 squlite3 在生产模式下运行 postgres?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56399398/

相关文章:

postgresql - Camunda Cockpit 和 Rest API 关闭但应用程序启动/JobExecutor 配置

iphone - 调试sqlite

ruby-on-rails - 带有 nokogiri 的空 html

ruby-on-rails - 在 Heroku 控制台上运行循环或多行代码

JavaScript 在生产环境中不起作用

ruby-on-rails - 评估字符串模板

postgresql - pglogical:列出复制集?

postgresql - Rails 和 ActiveRecord - 按纬度和经度划分的最近点

java - db.query 无法使用整数字段进行选择

c++ - 将准备好的语句与 sqlite 事务语句一起使用