为数据库适配器指定sqlite3但未加载gem

时间:2016-04-14 21:42:15

标签: ruby-on-rails ruby sqlite rubygems

我是Rails的新手并且正在尝试启动我的服务器。运行命令rails server生成错误

  

为数据库适配器指定'sqlite3',但未加载gem。将gem 'sqlite3'添加到您的Gemfile中(并确保其版本达到ActiveRecord所需的最低版本)。

我看了很多这些先前的问题,似乎没有人解决它。这是我的Gemfile代码

if RUBY_VERSION =~ /1.9/
   Encoding.default_external = Encoding::UTF_8
   Encoding.default_internal = Encoding::UTF_8
end

source 'https://rubygems.org'

gem 'rails', '~> 4.2.0'

gem 'ey_config'
gem 'rails_autolink'
gem 'simple_form'

# Assets
gem 'jquery-rails'
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'

platform :ruby do
   gem 'mysql2'
   gem 'pg'
   gem 'activerecord-postgis-adapter', '3.0.0.beta2'
   gem 'sqlite3'

   gem 'newrelic_rpm'
   gem 'unicorn'
   gem 'puma'
   gem 'json'
   gem 'minitest'
   gem 'psych'
   gem 'racc'
end

platforms :jruby do
   ar_jdbc_version = '~> 1.3'
   gem 'activerecord-jdbc-adapter', ar_jdbc_version
   gem 'activerecord-jdbcmysql-adapter', ar_jdbc_version
   gem 'activerecord-jdbcpostgresql-adapter', ar_jdbc_version
   gem 'activerecord-jdbcsqlite3-adapter', ar_jdbc_version
   gem 'jdbc-mysql', :require => false
   gem 'jdbc-sqlite3', :require => false
   gem 'jdbc-postgres', :require => false

   gem 'jruby-openssl'
   gem 'trinidad'
end

platform :rbx do
   gem 'rubysl'
   gem 'rubysl-test-unit', :require => false
end

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
   gem 'tzinfo-data'
end

这是我的database.yml文件

# SQLite version 3.x
#   gem install sqlite3
development:
   adapter: sqlite3
   database: db/development.sqlite3
   pool: 5
   timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
   adapter: sqlite3
   database: db/test.sqlite3
   pool: 5
   timeout: 5000

production:
   adapter: sqlite3
   database: db/production.sqlite3
   pool: 5
   timeout: 5000`

以下是我的rakefile中的代码:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake'

Listr::Application.load_tasks

task :travis => ['db:create:all', 'db:migrate', :default]

还将提供伴随答案的任何解释。感谢。

2 个答案:

答案 0 :(得分:1)

由于版本不匹配,您的sqlite3 gem没有在生产中加载。因此,gemfile as gem 'sqlite3', '~> 1.3.13'更新就可以了。将其保留在group :production, :test下,将代码推送到heroku会很好。

答案 1 :(得分:0)

你的sqlite3 gem没有加载,因为你在Gemfile中得到了它。从platform :ruby do中取出并将其放在该块之外,可能在gem 'rails', '~> 4.2.0'

之下