【问题标题】:SQLite used in production mode even if postgres is specified即使指定了 postgres,SQLite 也用于生产模式
【发布时间】:2015-12-05 13:07:13
【问题描述】:

我的 Rails 应用在开发模式下运行良好。然后我通过bundle install --without development test 切换到生产模式。当我尝试运行 rake (rake routes) 时,我收到此错误: "

rake 中止! Gem::LoadError: 为数据库指定'sqlite3' 适配器,但未加载 gem。将gem 'sqlite3' 添加到您的 宝石文件

我的 Gemfile 有:

group :development, :test do
  gem 'sqlite3', '1.3.10'
end
group :production do
  gem 'pg', '0.18.3'
  gem 'rails_12factor'
end

我的config/database.yml 看起来像:

default: &default
  pool: 5
  timeout: 5000

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

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

production:
  <<: *default
  adapter: postgresql
  database: prod
  username: produser

bundle install --without production test 之后的我的 Gemfile.lock 有

GEM
  remote: https://rubygems.org/
  specs:
     ...
    pg (0.18.3)
    ...
    rails_12factor (0.0.3)
    ...
    sqlite3 (1.3.10)
    ...

DEPENDENCIES
  ...
  pg (= 0.18.3)
  ...
  rails_12factor (0.0.3)
  ...
  sqlite3 (= 1.3.10)
  ...

BUNDLED WITH
  1.10.6

我已更新到 Ruby 2.2.3、Rails 4.2.4,完成 gem update systembundle update 均无济于事。

我的另一个问题是为什么sqlite3 gem 会在生产模式下出现在我的Gemfile.lock 中?同样,为什么pg gem 会出现在开发模式中?

感谢任何帮助。

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    rake routes 使用默认环境——即开发环境。

    您需要:

    rake routes RAILS_ENV=production
    

    或将 RAILS_ENV 环境变量设置为“生产”

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 2022-01-23
      • 2015-03-05
      相关资源
      最近更新 更多