V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
woz24416
V2EX  ›  问与答

在执行 bundle exec rake db:migrate 出现如下报错信息: rake aborted!NoMethodError: undefined method `accept' for nil:NilClass

  •  
  •   woz24416 · 2014-09-20 18:47:08 +08:00 · 5133 次点击
    这是一个创建于 3511 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在$ rails generate scaffold User name:string email:string这一步之后,在执行bundle exec rake db:migrate这条命令之后,出现如下报错信息:
    rake aborted!
    NoMethodError: undefined method `accept' for nil:NilClass

    使用环境如下:
    系统:OS X 10.9.5
    Ruby: ruby2.0.0p481
    Rails: 4.0.2

    Gemfile相关内容如下:
    gem 'rails', '4.0.2'
    gem 'mysql2', '0.2.6'
    gem 'sass-rails', '4.0.1'
    gem 'uglifier', '2.1.1'
    gem 'coffee-rails', '4.0.1'
    gem 'jquery-rails', '2.2.1'
    gem 'turbolinks', '1.1.1'
    gem 'jbuilder', '1.0.2'
    group :doc do
    # bundle exec rake doc:rails generates the API under doc/api.
    gem 'sdoc', '0.3.20', require: false
    end

    database.yml的内容如下:
    development:
    adapter: mysql2
    encoding: utf8
    database: demo_app_development
    pool: 5
    username: root
    password: rails
    host: 127.0.0.1
    port: 3306

    *** LOCAL GEMS ***

    actionmailer (4.0.2)
    actionpack (4.0.2)
    activemodel (4.0.2)
    activerecord (4.0.2)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.2)
    arel (4.0.2)
    bigdecimal (1.2.0)
    builder (3.1.4)
    bundler (1.6.2)
    bundler-unload (1.0.2)
    coffee-rails (4.0.1)
    coffee-script (2.3.0)
    coffee-script-source (1.8.0)
    erubis (2.7.0)
    execjs (2.2.1)
    executable-hooks (1.3.2)
    gem-wrappers (1.2.4)
    hike (1.2.3)
    i18n (0.7.0.beta1, 0.6.11)
    io-console (0.4.2)
    jbuilder (1.5.3, 1.0.2)
    jquery-rails (3.1.2, 2.2.1)
    json (1.8.1, 1.7.7)
    mail (2.5.4)
    mime-types (1.25.1)
    minitest (4.7.5, 4.3.2)
    multi_json (1.10.1)
    mysql2 (0.3.16, 0.3.11, 0.2.6)
    polyglot (0.3.5)
    psych (2.0.0)
    rack (1.5.2)
    rack-test (0.6.2)
    rails (4.0.2)
    railties (4.0.2)
    rake (10.3.2, 0.9.6)
    rdoc (4.1.2, 4.0.0, 3.12.2)
    rubygems-bundler (1.4.4)
    rvm (1.11.3.9)
    sass (3.4.5, 3.4.4, 3.2.19)
    sass-rails (4.0.3, 4.0.1)
    sdoc (0.4.1, 0.3.20)
    sprockets (2.12.2, 2.11.0)
    sprockets-rails (2.0.1)
    sqlite3 (1.3.9, 1.3.8)
    test-unit (2.0.0.0)
    thor (0.19.1)
    thread_safe (0.3.4)
    tilt (1.4.1)
    treetop (1.4.15)
    turbolinks (2.3.0, 1.1.1)
    tzinfo (0.3.41)
    uglifier (2.5.3, 2.1.1)

    恳请得到诸位的帮助,万分感谢!!!
    9 条回复    2014-09-22 07:48:02 +08:00
    roamlog
        1
    roamlog  
       2014-09-20 19:01:46 +08:00 via iPhone   ❤️ 1
    Mysql2 版本太低
    woz24416
        2
    woz24416  
    OP
       2014-09-20 19:21:40 +08:00
    但是如果把mysql2的版本升高的话,在rails server这条命令执行后就会报错,我查找和尝试了多次,才在0.2.6这个版本后rails server才能够顺利执行。但不知道能够这两条命令都能够执行的版本是多少呢?抑或有其他的解决方法?多谢!
    roamlog
        3
    roamlog  
       2014-09-20 19:27:18 +08:00 via iPhone
    给出升高版本后的错误信息看看,另外关于 Rails 的人问题去 rubychina 提会更有效果
    woz24416
        4
    woz24416  
    OP
       2014-09-21 08:59:26 +08:00
    @roamlog Incorrect MySQL client library version! This gem was compiled for 5.6.20 but the client library is 5.5.28. (RuntimeError)

    如上是将Gemfile中mysql的版本号去掉后,rails serrver的报错信息。

    PS:此时的mysql2: Using mysql2 0.3.16 (was 0.2.6)
    woz24416
        6
    woz24416  
    OP
       2014-09-21 18:09:14 +08:00
    @roamlog 谢谢! 但是这条我之前也搜到过,我这边的系统是osx,看文章里面说的应该是windows系统的解决方案,不知道怎样转换到osx上面呢?
    roamlog
        7
    roamlog  
       2014-09-21 18:49:31 +08:00
    @woz24416 把你安装的 mysql2 gem 都卸载了,如果有必要把 Mysql 更新到最新版什么的
    woz24416
        8
    woz24416  
    OP
       2014-09-22 02:18:03 +08:00
    @roamlog 您的意思是:MYSQL2Gem卸载然后再重新安装还是有什么其他方法呢?
    roamlog
        9
    roamlog  
       2014-09-22 07:48:02 +08:00 via iPhone
    @woz24416 嗯,把 mysql2 gem 都卸载了,重新安装,如果还不行就连 mysql 也卸载了重装
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2194 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:29 · PVG 19:29 · LAX 04:29 · JFK 07:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.