Gem::LoadError:添加'Gem';mysql';`到你的档案
在遵循本指南时,我一直遇到此错误: 跑步Gem::LoadError:添加'Gem';mysql';`到你的档案,mysql,ruby-on-rails,ruby,sqlite,gem,Mysql,Ruby On Rails,Ruby,Sqlite,Gem,在遵循本指南时,我一直遇到此错误: 跑步 Gem::LoadError: Specified 'mysql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your Gemfile. 在搜索了一段时间后,我被告知需要修改gem文件,添加gem'mysql',然后运行bundle安装。但是,我无法在列表中看到mysql $ cd activerecord $ bundle exec rake test_
Gem::LoadError: Specified 'mysql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your Gemfile.
在搜索了一段时间后,我被告知需要修改gem文件
,添加gem'mysql'
,然后运行bundle安装
。但是,我无法在列表中看到mysql
$ cd activerecord
$ bundle exec rake test_sqlite3
Gemfile
Resolving dependencies...
Using rake (10.1.0)
Using i18n (0.6.5)
Using json (1.8.0)
Using minitest (5.0.8)
Using atomic (1.1.14)
Using thread_safe (0.1.3)
Using tzinfo (0.3.38)
Using activesupport (4.1.0.beta) from source at .
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.1.0.beta) from source at .
Using builder (3.1.4)
Using activemodel (4.1.0.beta) from source at .
Using erubis (2.7.0)
Using actionview (4.1.0.beta) from source at .
Using mime-types (1.25)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.1.0.beta) from source at .
Using arel (4.0.0)
Using activerecord (4.1.0.beta) from source at .
Using bcrypt-ruby (3.1.2)
Using benchmark-ips (1.2.0)
Using bundler (1.3.5)
Using coffee-script-source (1.6.3)
Using execjs (2.0.2)
Using coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.1.0.beta) from source at .
Using coffee-rails (4.0.0)
Using columnize (0.3.6)
Using dalli (2.6.4)
Using debugger-linecache (1.2.0)
Using debugger-ruby_core_source (1.2.3)
Using debugger (1.6.2)
Using hike (1.2.3)
Using jquery-rails (2.2.2)
Using mustache (0.99.4)
Using mini_portile (0.5.1)
Using nokogiri (1.6.0)
Using kindlerb (0.1.1)
Using metaclass (0.0.1)
Using mocha (0.14.0)
Using multi_json (1.8.1)
Using racc (1.4.9)
Using rack-cache (1.2)
Using tilt (1.4.1)
Using sprockets (2.10.0)
Using sprockets-rails (2.0.0)
Using rails (4.1.0.beta) from source at .
Using rdoc (3.12.2)
Using redcarpet (2.2.2)
Using sdoc (0.3.20)
Using sqlite3 (1.3.8)
Using turbolinks (1.3.0)
Using uglifier (2.2.1)
Using w3c_validators (1.2)
Using yajl-ruby (1.1.0)
Your bundle is complete!
Gems in the group db were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ cd rails
$ bundle exec rails new ~/my-test-app --dev
但是,如果我运行gem list
,我的输出如下:
source 'https://rubygems.org'
gem 'rails', path: '/home/terence/rails'
gem 'arel', github: 'rails/arel'
gem 'mysql', '~> 2.9.1'
gem 'mysql2', '~> 0.3.13'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use edge version of sprockets-rails
gem 'sprockets-rails', github: 'rails/sprockets-rails'
# Use SCSS for stylesheets
gem 'sass-rails', github: 'rails/sass-rails'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', github: 'rails/coffee-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
# Run `rails console` in the browser. Read more: https://github.com/rails/web-console
gem 'web-console', group: :development
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
数据库.yml
*** LOCAL GEMS ***
actionmailer (4.0.0)
actionpack (4.0.0)
activemodel (4.0.0)
activerecord (4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.0)
arel (4.0.0)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
benchmark-ips (1.2.0)
builder (3.1.4)
bundler (1.3.5)
bundler-unload (1.0.2)
celluloid (0.15.2)
chunky_png (1.2.8)
coderay (1.0.9)
coffee-rails (4.0.0)
coffee-script (2.2.0)
coffee-script-source (1.6.3)
columnize (0.3.6)
compass (0.12.2)
cyaml (0.0.45)
dalli (2.6.4)
debugger (1.6.2)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.3)
em-websocket (0.5.0)
erubis (2.7.0)
eventmachine (1.0.3)
execjs (2.0.2)
executable-hooks (1.2.3)
ffi (1.9.0)
formatador (0.2.4)
fssm (0.2.10)
guard (2.0.3)
guard-compass (1.0.0)
guard-haml (1.1.0)
guard-livereload (2.0.0)
haml (4.0.3)
hike (1.2.3)
http_parser.rb (0.5.3)
i18n (0.6.5)
jbuilder (1.5.1)
jquery-rails (3.0.4, 2.2.2)
json (1.8.0)
kindlerb (0.1.1)
listen (2.0.1)
lumberjack (1.0.4)
mail (2.5.4)
metaclass (0.0.1)
method_source (0.8.2)
mime-types (1.25)
mini_portile (0.5.1)
minitest (5.0.8, 4.7.5)
mocha (0.14.0)
multi_json (1.8.1)
mustache (0.99.4)
mysql (2.9.1)
mysql2 (0.3.13)
nokogiri (1.6.0)
polyglot (0.3.3)
pry (0.9.12.2)
racc (1.4.9)
rack (1.5.2)
rack-cache (1.2)
rack-test (0.6.2)
rails (4.0.0)
railties (4.0.0)
rake (10.1.0)
rb-fsevent (0.9.3)
rb-inotify (0.9.2)
rdoc (3.12.2)
redcarpet (2.2.2)
rubygems-bundler (1.3.4)
rvm (1.11.3.8)
sass (3.2.12)
sass-rails (4.0.0)
sdoc (0.3.20)
slop (3.4.6)
sprockets (2.10.0)
sprockets-rails (2.0.0)
sqlite3 (1.3.8)
thor (0.18.1)
thread_safe (0.1.3)
tilt (1.4.1)
timers (1.1.0)
treetop (1.4.15)
turbolinks (1.3.0)
tzinfo (0.3.38, 0.3.37)
uglifier (2.2.1)
w3c_validators (1.2)
web-console (1.0.3)
yajl-ruby (1.1.0)
请帮忙?解决了:我花了一段时间才弄明白,我把责任归咎于导游。无论如何,请确保您正在编辑正确的Gemfile,并使用您更改的
Gemfile
在目录中进行bundle安装。当我跑的时候
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem '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
这实际上在我的主目录中创建了一个名为my test app
(其中包含一个Gemfile)的文件夹,但我必须在我的rails目录(其中也包含一个Gemfile)中运行$bundle exec rake test\u sqlite3
查看我上面的输出,它说没有安装组db中的gem。
当我运行bundle install
时,指的是我的Gemfile
中没有执行的行,它们恰好是安装mysql、mysql2和postgresql的gem行。我这样更正了文件:
Gemfile
Resolving dependencies...
Using rake (10.1.0)
Using i18n (0.6.5)
Using json (1.8.0)
Using minitest (5.0.8)
Using atomic (1.1.14)
Using thread_safe (0.1.3)
Using tzinfo (0.3.38)
Using activesupport (4.1.0.beta) from source at .
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.1.0.beta) from source at .
Using builder (3.1.4)
Using activemodel (4.1.0.beta) from source at .
Using erubis (2.7.0)
Using actionview (4.1.0.beta) from source at .
Using mime-types (1.25)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.1.0.beta) from source at .
Using arel (4.0.0)
Using activerecord (4.1.0.beta) from source at .
Using bcrypt-ruby (3.1.2)
Using benchmark-ips (1.2.0)
Using bundler (1.3.5)
Using coffee-script-source (1.6.3)
Using execjs (2.0.2)
Using coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.1.0.beta) from source at .
Using coffee-rails (4.0.0)
Using columnize (0.3.6)
Using dalli (2.6.4)
Using debugger-linecache (1.2.0)
Using debugger-ruby_core_source (1.2.3)
Using debugger (1.6.2)
Using hike (1.2.3)
Using jquery-rails (2.2.2)
Using mustache (0.99.4)
Using mini_portile (0.5.1)
Using nokogiri (1.6.0)
Using kindlerb (0.1.1)
Using metaclass (0.0.1)
Using mocha (0.14.0)
Using multi_json (1.8.1)
Using racc (1.4.9)
Using rack-cache (1.2)
Using tilt (1.4.1)
Using sprockets (2.10.0)
Using sprockets-rails (2.0.0)
Using rails (4.1.0.beta) from source at .
Using rdoc (3.12.2)
Using redcarpet (2.2.2)
Using sdoc (0.3.20)
Using sqlite3 (1.3.8)
Using turbolinks (1.3.0)
Using uglifier (2.2.1)
Using w3c_validators (1.2)
Using yajl-ruby (1.1.0)
Your bundle is complete!
Gems in the group db were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ cd rails
$ bundle exec rails new ~/my-test-app --dev
我找到了这个错误的另一个原因。虽然我安装了mysql2 gem,但在我的模型中,我指定了字符串“mysql”来建立连接:
# AR
gem 'sqlite3', '~> 1.3.6'
gem 'mysql', '~> 2.9.1'
gem 'mysql2', '~> 0.3.13'
gem 'pg', '~> 0.17.0'
group :db do
# gem 'pg', '>= 0.11.0'
# gem 'mysql', '>= 2.9.0'
# gem 'mysql2', '>= 0.3.13'
end
显然,它应该是“mysql2”而不是“mysql”。我也有同样的问题。解决办法是我忘记相应地调整GEM文件。因此,请切换到创建rails应用程序的目录,然后使用sudo vim Gemfile
打开Gemfile。
在那里你必须添加或删除某些宝石,根据你的需要。
在我的例子中,我必须用“mysql”交换db gem“sqlite3”。
之后,使用:wq
保存文件,并再次运行rails generate[model/controller/view]
这已经完成了我的工作,希望它能帮助你们中的一些人