问题描述
我见过其他类似的问题(例如 this one),但略有不同。
我使用命令 rails new backend -d=postgresql -T --api
创建了一个全新的 Rails API 应用程序。我已将数据库全部设置并连接正常。现在我正在尝试安装 graphql gem。它在我的 Gemfile 中,我已经运行了 bundle install
,下一步是根据文档运行命令 bundle exec rails generate graphql:install
。但是,当我运行它时,出现此错误:
/Users/jimmiejackson/.rvm/gems/ruby-2.5.5/gems/bundler-2.2.11/lib/bundler/rubygems_integration.rb:334:in `block (2 levels) in replace_gem': Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile. (LoadError)
from /Users/jimmiejackson/.rvm/gems/ruby-2.5.5/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `<top (required)>'
from ...
from ...
我在 Github 问题、Google 或 Stack 中找不到任何答案。我不知道为什么当我从新安装 postgresql 时会收到 sqlite 错误。我上次开发 Rails 应用已经有一段时间了,可能是什么问题?
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.5'
gem 'rails','~> 6.0.3','>= 6.0.3.5'
gem 'pg','>= 0.18','< 2.0'
gem 'puma','~> 4.1'
gem 'bcrypt','~> 3.1.7'
gem 'graphql','1.9.17'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap','>= 1.4.2',require: false
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS),making cross-origin AJAX possible
gem 'rack-cors'
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]
end
group :development do
gem 'listen','~> 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'
gem 'graphiql-rails','1.7.0'
end
# Windows does not include zoneinfo files,so bundle the tzinfo-data gem
gem 'tzinfo-data',platforms: [:mingw,:mswin,:x64_mingw,:jruby]
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: movie_show_tracker_development
test:
<<: *default
database: movie_show_tracker_test
解决方法
好吧,我终于搞定了。我最终不得不重新从头开始这个项目,并使用 Ruby v.2.6.3/Rails v.6.0.3.5 来让 graphql gem 正常工作。甚至不确定这些是否是罪魁祸首,但它现在似乎起作用了!