【问题标题】:Gem::LoadError: Error loading the 'sqlite3' Active Record adapterGem::LoadError: 加载“sqlite3”Active Record 适配器时出错
【发布时间】:2018-09-24 10:46:14
【问题描述】:

我在做heroku run rake db:migrate 这是错误:

Gem::LoadError:加载“sqlite3”Active Record 适配器时出错。 缺少它所依赖的宝石? sqlite3 不是捆绑包的一部分。添加它 到您的 Gemfile。

宝石文件:

group :production do
  gem 'pg', '~> 0.18'
end

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
end

group :development do
  # Access an interactive console on exception pages or by calling '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'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

Database.yml

production:
  adapter: postgresql
  encoding: Unicode    

【问题讨论】:

  • grep -r sqlite3 . 在您的 Rails 根目录中。
  • 你添加rails_12factorgem了吗?
  • 你的RAILS_ENV 是什么?那是开发还是测试?

标签: ruby-on-rails ruby heroku


【解决方案1】:

我遇到了同样的问题,我通过降级默认安装 rails new 的版本解决了它。

使用“gem uninstall sqlite3”删除当前版本的 sqlite3 gem,然后修改 GemFile 以包含 sqlite3 版本。我的情况是我设置了版本'~1.3.6' 并且解决了问题

【讨论】:

  • 我认为版本应该是'~1.3.6'。使用 gem 'sqlite3', '~> 1.3.6' 代替
【解决方案2】:

如果您尝试使用除 sqlite 以外的其他数据库,

  1. 删除 gemfile 中的 sqlite3 并捆绑安装

  2. 删除 database.yml 中的 sqlite3

  3. rake db:create

【讨论】:

    【解决方案3】:

    Rails 5 及以下您需要'rails_12factor'gem.... Rails 5 及以上这不是必需的。

    还注意到您的开发环境中没有 sqlite3,这可能无关紧要,但只需将其放在那里即可。

    【讨论】:

    • “5 及以下... 5 及以上”不明确。 Rails 5 是否需要该宝石? I guess not.
    • 不是。很可能 sqlite 版本只需要在 Gemfile 中修复:gem 'sqlite3', '~&gt; 1.4.0'(或其他版本)
    • 您的表述有误:您暗示 Rails 5 需要和不需要 rails_12factor。
    猜你喜欢
    • 1970-01-01
    • 2022-11-11
    • 2020-11-24
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 2020-03-25
    • 2020-05-11
    • 1970-01-01
    相关资源
    最近更新 更多