我见过其他类似的问题(比如这个),但是略有不同。
我使用命令创建了一个全新的 Rails API 应用程序rails new backend -d=postgresql -T --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 中找不到任何答案。我不确定为什么当我从 new 安装 postgresql 时会出现 sqlite 错误。自从我上次开发 Rails 应用程序以来已经有一段时间了,可能是什么问题?
宝石文件:
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]
数据库.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