我已经安装了 mysql gem 但仍然显示此错误
I had installed mysql gem but still showing this error
D:\Projects\Ruby on Rails\Library>rails generate model Book
invoke active_record
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_record/connect
ion_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'mys
ql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your G
emfile (and ensure its version is at the minimum required by ActiveRecord). (Gem
::LoadError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/connection_adapters/connection_specification.rb:174:in `spec'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/connection_handling.rb:50:in `establish_connection'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:38:in `instance_eval'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:38:in `execute_hook'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:44:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:44:in `run_load_hooks'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/base.rb:316:in `<module:ActiveRecord>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/base.rb:26:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/genera
tors/named_base.rb:179:in `pluralize_table_names?'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/genera
tors/named_base.rb:119:in `table_name'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/rails/ge
nerators/active_record/model/model_generator.rb:21:in `create_migration_file'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/command.rb
:27:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:126:in `invoke_command'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `block in invoke_all'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `map'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `invoke_all'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:2
32:in `dispatch'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:115:in `invoke'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:2
77:in `block in _invoke_for_class_method'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/shell.rb:6
8:in `with_padding'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:2
66:in `_invoke_for_class_method'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:1
49:in `_invoke_from_option_orm'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/command.rb
:27:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:126:in `invoke_command'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `block in invoke_all'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `map'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `invoke_all'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:2
32:in `dispatch'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/base.rb:44
0:in `start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/genera
tors.rb:157:in `invoke'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/generate.rb:13:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/dependencies.rb:274:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/dependencies.rb:274:in `block in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/dependencies.rb:240:in `load_dependency'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/dependencies.rb:274:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/commands_tasks.rb:123:in `require_command!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/commands_tasks.rb:130:in `generate_or_destroy'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/commands_tasks.rb:50:in `generate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/commands_tasks.rb:39:in `run_command!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
- 确保仔细检查您的 gemfile。
我的 Gemfile:
gem 'mysql2', '~> 0.3'
进行捆绑安装。
验证您的 database.yml 文件。
database.yml:
development:
adapter: mysql2
encoding: utf8
database: mydatabase
username: myusername
password: mypass123
host: localhost
pool: 5
port: 3306
timeout: 5000
我遇到了同样的问题,我所能得到的是 gem 版本 0.4.0 与 rails 4.2.4 一起使用时出现问题,我所做的就是修复它转到我的 Gemfile 并将 gem 版本更改为 mysql:
gem 'mysql2'
对于这个
gem 'mysql2', '~> 0.3.20'
然后 运行:
bundle install
而且效果很好
希望对你有用!
D:\Projects\Ruby on Rails\Library>rails generate model Book
invoke active_record
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_record/connect
ion_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'mys
ql' for database adapter, but the gem is not loaded. Add `gem 'mysql'` to your G
emfile (and ensure its version is at the minimum required by ActiveRecord). (Gem
::LoadError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/connection_adapters/connection_specification.rb:174:in `spec'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/connection_handling.rb:50:in `establish_connection'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:38:in `instance_eval'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:38:in `execute_hook'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:44:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/lazy_load_hooks.rb:44:in `run_load_hooks'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/base.rb:316:in `<module:ActiveRecord>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/active_r
ecord/base.rb:26:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/genera
tors/named_base.rb:179:in `pluralize_table_names?'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/genera
tors/named_base.rb:119:in `table_name'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-4.2.0/lib/rails/ge
nerators/active_record/model/model_generator.rb:21:in `create_migration_file'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/command.rb
:27:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:126:in `invoke_command'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `block in invoke_all'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `map'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `invoke_all'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:2
32:in `dispatch'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:115:in `invoke'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:2
77:in `block in _invoke_for_class_method'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/shell.rb:6
8:in `with_padding'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:2
66:in `_invoke_for_class_method'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:1
49:in `_invoke_from_option_orm'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/command.rb
:27:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:126:in `invoke_command'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `block in invoke_all'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `map'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation
.rb:133:in `invoke_all'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:2
32:in `dispatch'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.19.1/lib/thor/base.rb:44
0:in `start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/genera
tors.rb:157:in `invoke'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/generate.rb:13:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/dependencies.rb:274:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/dependencies.rb:274:in `block in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/dependencies.rb:240:in `load_dependency'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.2.0/lib/active_
support/dependencies.rb:274:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/commands_tasks.rb:123:in `require_command!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/commands_tasks.rb:130:in `generate_or_destroy'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/commands_tasks.rb:50:in `generate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds/commands_tasks.rb:39:in `run_command!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.2.0/lib/rails/comman
ds.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
- 确保仔细检查您的 gemfile。
我的 Gemfile:
gem 'mysql2', '~> 0.3'
进行捆绑安装。
验证您的 database.yml 文件。
database.yml:
development:
adapter: mysql2
encoding: utf8
database: mydatabase
username: myusername
password: mypass123
host: localhost
pool: 5
port: 3306
timeout: 5000
我遇到了同样的问题,我所能得到的是 gem 版本 0.4.0 与 rails 4.2.4 一起使用时出现问题,我所做的就是修复它转到我的 Gemfile 并将 gem 版本更改为 mysql:
gem 'mysql2'
对于这个
gem 'mysql2', '~> 0.3.20'
然后 运行:
bundle install
而且效果很好
希望对你有用!