启动rails5服务器时sqlite3加载错误

时间:2016-09-16 10:43:21

标签: ruby-on-rails ruby sqlite ruby-on-rails-5

我使用ruby安装程序和rails 5在windows 10 64bit上使用ruby devkit安装ruby版本2.3.1p112然后运行命令:

rails new app

我得到了我的新应用目录,然后在其中cd然后运行

bundle install rails s

但我得到了这个错误:

LoadError (Could not load 'active_record/connection_adapters/sqlite3_adapter'.
Make sure that the adapter in config/database.yml is valid.
If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3'
add the necessary adapter gem to the Gemfile.):

我在第10行编辑sqlite3-1.3.11-x86-mingw32.gemspec文件:

s.require_paths = ["lib"]

到此:

s.require_paths = ["lib/sqlite3_native"]

但出现同样的错误。

datebase.yml

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

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

# 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:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

这是我的Gemfile

source 'https://rubygems.org'

# Use credit_debit_card_number_validator to validate and generate card numbers
gem 'credit_debit_card_number_validator'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri

  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

这是Application trace

This error occurred while loading the following files:

active_record /碱

最后这是Framework trace

activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `require'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `block in require'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `require'
activerecord (5.0.0.1) lib/active_record/connection_adapters/sqlite3_adapter.rb:8:in `<top (required)>'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `require'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `block in require'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `require'
activerecord (5.0.0.1) lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
activerecord (5.0.0.1) lib/active_record/connection_handling.rb:53:in `establish_connection'
activerecord (5.0.0.1) lib/active_record/railtie.rb:125:in `block (2 levels) in <class:Railtie>'
activesupport (5.0.0.1) lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
activesupport (5.0.0.1) lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
activesupport (5.0.0.1) lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
activesupport (5.0.0.1) lib/active_support/lazy_load_hooks.rb:44:in `each'
activesupport (5.0.0.1) lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
activerecord (5.0.0.1) lib/active_record/base.rb:324:in `<module:ActiveRecord>'
activerecord (5.0.0.1) lib/active_record/base.rb:24:in `<top (required)>'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `require'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `block in require'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
activesupport (5.0.0.1) lib/active_support/dependencies.rb:293:in `require'
activerecord (5.0.0.1) lib/active_record/migration.rb:558:in `connection'
activerecord (5.0.0.1) lib/active_record/migration.rb:545:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.3.1) lib/web_console/middleware.rb:131:in `call_app'
web-console (3.3.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.3.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.3.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.0.1) lib/rails/engine.rb:522:in `call'
puma (3.6.0) lib/puma/configuration.rb:225:in `call'
puma (3.6.0) lib/puma/server.rb:578:in `handle_request'
puma (3.6.0) lib/puma/server.rb:415:in `process_client'
puma (3.6.0) lib/puma/server.rb:275:in `block in run'
puma (3.6.0) lib/puma/thread_pool.rb:116:in `block in spawn_thread'

1 个答案:

答案 0 :(得分:0)

首先尝试

gem uninstall sqlite3

然后运行

bundle install 

如果这不起作用,请确保您没有用户名和密码,并且您的环境变量没问题。

最后只是一个建议,尝试使用postgresql,因为它在生产中会更有帮助。