问题描述
我只是想获得在3.1下运行的Rails应用程序的最基本外壳,当我运行bundle exec rake db:migrate-
I'm just trying to get the most basic of basic shell of a rails app running under 3.1, and I'm getting this weird error when I run bundle exec rake db:migrate-
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.6), already activated mysql2-0.3.2. Make sure all dependencies are added to Gemfile.)
我在这里和其他地方读过的所有文章都说我应该对Rails 3.1使用较新的mysql2适配器,所以我有-
All the posts that I've read here and elsewhere say I should be using the newer mysql2 adaptor for rails 3.1, so I have-
gem 'mysql2', '0.3.2'
在我的gemfile中.一些帖子建议使用-
in my gemfile. Some post have suggested using-
gem 'mysql2', '~> 0.3'
但是那给了我同样的错误.宝石安装在-
but that gets me the same error. The gem is installed at-
/Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/mysql2-0.3.2
建议我再次在我的gemfile中切换该行,这一次是
It was suggested that I switch up that line in my gemfile again, this time to be-
gem 'mysql2', '< 0.3'
但是,当我这样做时,请运行bundle install,然后尝试再次运行迁移,我会得到-
but when I do that, run bundle install, and then try to run migrations again, I get-
An error has occurred, all later migrations canceled:
undefined method `rows' for nil:NilClass
我完整的迁移文件看起来像这样-
My complete migration file looks like this-
class CreatePlaces < ActiveRecord::Migration
def change
create_table :places do |t|
t.string :title
t.string :meta_description
t.string :permalink, :limit => 60
t.string :name, :limit => 60
t.string :address
t.string :state, :limit => 2
t.string :region, :limit => 3
t.float :latitude
t.float :longitude
t.text :description
t.boolean :active, :default => true
t.timestamps
end
add_index :places, [:permalink, :state, :region, :latitude, :longitude, :active], :name => 'places_index'
end
end
运行该迁移的完整输出为-
And the full output of running that migration is-
== CreatePlaces: migrating ===================================================
-- create_table(:places)
-> 0.0925s
-- add_index(:places, [:permalink, :state, :region, :latitude, :longitude, :active], {:name=>"places_index"})
-> 0.1097s
== CreatePlaces: migrated (0.2023s) ==========================================
rake aborted!
An error has occurred, all later migrations canceled:
undefined method `rows' for nil:NilClass
没有以后的迁移,这是唯一的迁移,因为这是一个我刚刚开始尝试使Rails 3.1正常运行的应用程序.删除数据库并重新创建它会使我到达同一位置.
There are no later migrations, that's the only one, as this is an app that I'm just starting to try to get Rails 3.1 running properly. Dropping the database and recreating it gets me to the same place.
我可以从控制台访问地方-
I am able to access Places from the console-
ruby-1.9.2-p180 :001 > Place
(0.3ms) SHOW TABLES
(0.1ms) SHOW TABLES
(1.1ms) describe `places`
=> Place(id: integer, title: string, meta_description: string, permalink: string, name: string, address: string, state: string, region: string, latitude: float, longitude: float, description: text, active: boolean, created_at: datetime, updated_at: datetime)
但是当我实际上尝试在地方信息"上进行查找或任何操作时,出现以下错误-
But when I actually try to do a find or anything on Places, I get the following error-
Place.find(:all)
ArgumentError: wrong number of arguments (3 for 2)
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:634:in `select'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/connection_adapters/abstract/database_statements.rb:9:in `select_all'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:470:in `find_by_sql'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/relation.rb:111:in `to_a'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/relation/finder_methods.rb:155:in `all'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/relation/finder_methods.rb:105:in `find'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:437:in `find'
from (irb):2
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/railties-3.1.0.rc5/lib/rails/commands/console.rb:45:in `start'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/railties-3.1.0.rc5/lib/rails/commands/console.rb:8:in `start'
from /Users/mark/.rvm/gems/ruby-1.9.2-p180@rails310pre/gems/railties-3.1.0.rc5/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
有人有什么想法吗?我已经挖了大约18个小时了,只是围着圈子跑.
Anyone have any ideas? I've been digging for like 18 hours now, and just running in circles.
谢谢,-马克
推荐答案
Active Record对与mysql2
版本兼容的内容有其自己的要求.这是代码行 Rails 3.1.您必须使用满足这些要求的mysql2
版本.
Active Record has it's own requirements on which versions of mysql2
are compatible. Here's the line of code for Rails 3.1. You must use a version of mysql2
that satisfies these requirements.
这表示Rails期望mysql2
版本大于0.3.6且小于0.4.0,但找到的版本为0.3.2.如果您将Gemfile更改为请求此范围内的版本,则Active Record应该很满意.也许
This is saying Rails expects a mysql2
version greater than 0.3.6 and less than 0.4.0, but found version 0.3.2. If you change your Gemfile to request a version in this range then Active Record should be happy. Perhaps
gem 'mysql2', '0.3.6'
别忘了更改Gemfile后更新软件包.
Don't forget to update your bundle after changing your Gemfile.
bundle update mysql2
这篇关于无法激活mysql2(〜> 0.3.6),已经在Rails 3.1中激活了mysql2-0.3.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!