AliOsm AliOsm - 2 months ago 34
Ruby Question

sqlite3 load error while start rails5 server

I'v install ruby version 2.3.1p112 with ruby devkit on windows 10 64bit using ruby installer and rails 5 then run command:

rails new app


I'v got my new app directory then I
cd
in it then run

bundle install
rails s


but I'v got this error:

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.):


I'v edit
sqlite3-1.3.11-x86-mingw32.gemspec
file in line 10 from this:

s.require_paths = ["lib"]


to this:

s.require_paths = ["lib/sqlite3_native"]


but the same error appear.

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


This is my
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]


and this is
Application trace
:

This error occurred while loading the following files:


active_record/base

finally this is
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'

Answer

First try

gem uninstall sqlite3

then run

bundle install 

If that didn't work make sure you don't have a username and password and your Environment variable are ok.

Last just a word of advice try to use postgresql as it'll be more helpful in production.