我认为这是一个常见的问题,但我已经尝试了其他几篇文章中我读过的内容,并且我遇到了同样的命运。
我使用rbenv,因为这是我第一次遇到的。
rake db:create
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/mysql_database_tasks.rb:8:in `establish_connection'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/mysql_database_tasks.rb:15:in `create'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:93:in `create'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/cmunger/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/cmunger/.rbenv/versions/2.2.3/bin/rake:33:in `<main>'
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"blogApp", "password"=>"*****", "socket"=>"/tmp/mysql.sock", "database"=>"blog_test"}
rake aborted!
Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Gem::LoadError: can't activate mysql2 (~> 0.3.13), already activated mysql2-0.4.2. Make sure all dependencies are added to Gemfile
我的版本和捆绑安装。 mysql2在那里......
cmunger@Claytons-Mac:~/Desktop/Devlopment/blog$ rbenv versions
system
* 2.2.3 (set by RBENV_VERSION environment variable)
cmunger@Claytons-Mac:~/Desktop/Devlopment/blog$ bundle install
Using actionmailer 4.2.4
Using actionpack 4.2.4
Using actionview 4.2.4
Using activejob 4.2.4
Using activemodel 4.2.4
Using activerecord 4.2.4
Using activesupport 4.2.4
Using arel 6.0.3
Using binding_of_caller 0.7.2
Using builder 3.2.2
Using bundler 1.10.6
Using byebug 8.2.1
Using coffee-rails 4.1.0
Using coffee-script 2.4.1
Using coffee-script-source 1.10.0
Using concurrent-ruby 1.0.0
Using debug_inspector 0.0.2
Using erubis 2.7.0
Using execjs 2.6.0
Using globalid 0.3.6
Using i18n 0.7.0
Using jbuilder 2.3.2
Using jquery-rails 4.0.5
Using json 1.8.3
Using loofah 2.0.3
Using mail 2.6.3
Using mime-types 2.99
Using mini_portile2 2.0.0
Using minitest 5.8.3
Using multi_json 1.11.2
Using mysql2 0.4.2
Using nokogiri 1.6.7
Using rack 1.6.4
Using rack-test 0.6.3
Using rails 4.2.4
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.7
Using rails-html-sanitizer 1.0.2
Using railties 4.2.4
Using rake 10.4.2
Using rdoc 4.2.0
Using sass 3.4.20
Using sass-rails 5.0.4
Using sdoc 0.4.1
Using spring 1.5.0
Using sprockets 3.5.2
Using sprockets-rails 2.3.3
Using thor 0.19.1
Using thread_safe 0.3.5
Using tilt 2.0.1
Using turbolinks 2.5.3
Using tzinfo 1.2.2
Using uglifier 2.7.2
Using web-console 2.2.1
Bundle complete! 12 Gemfile dependencies, 54 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
我认为下面的错误可能是我问题的根源:
Gem::LoadError: can't activate mysql2 (~> 0.3.13), already activated mysql2-0.4.2. Make sure all dependencies are added to Gemfile
我试着改回来,但我明白了:
gem 'mysql2', '~> 0.4.2'
ERROR: While executing gem ... (Gem::CommandLineError)
Unknown command mysql2,
我可以提供的任何进一步信息请询问。我使用rbenv在安装上关注了一个wiki,这就是我所处的位置。
答案 0 :(得分:8)
除非您运行的是Rails 4.2.5或更高版本,否则您需要在Gemfile
中添加以下内容:
gem 'mysql2', '~> 0.3.10'
答案 1 :(得分:3)
您需要在命令中添加TextBox
,否则在全局gemset上执行它:
For i = 1 To 30
Dim item As New ListViewItem(i.ToString())
item.SubItems.Add(DateTime.Now.AddHours(i))
Me.ListView1.Items.Add(item)
Next
作为替代方案,您可以使用binstubs:
bundle exec
答案 2 :(得分:2)
for Rails 4.2.5或更高版本使用此
gem 'mysql2', '~> 0.3.18'
然后
bundle install
答案 3 :(得分:1)
在你的gemfile中只使用(现在)
gem mysql2
在命令行中,运行
$ gem install -v '0.3.13'
$ bundle exec bundle update
$ bundle exec bundle install
答案 4 :(得分:0)
给已经尝试过上述所有方法但仍然面临同样问题的任何人的一些额外建议。
我最初尝试过
rbenv global
和 rbenv local
设置为所需的版本.ruby-version
文件设置为所需的版本
4、将建议的rbenv条目放入我的.bash_profilerbenv version
测试了我的设置并达到了我的预期没有任何效果。
最后,经过几个小时的敲击和尝试不同的事情后,最终解决了这种情况的是重新启动。所以只是一个提示:如果所有这些建议都失败了,不要像我一样浪费时间:重启。
我在运行 bundle install
时第一次遇到这个问题。上面列出的 rbenv 步骤结合重启解决了这个问题。然后问题又出现在 rails db:create
命令上,即使 bundle install
仍在同一个 bash 会话中工作!我再次检查了所有内容,最终修复的是重新启动。