Rails mysql2 未定义方法“accept” for nil:NilClass

2024-04-03

我知道这里已经有一百万次了,但尝试了一切,但我仍然收到此错误:

$ rake db:migrate
rake aborted!
undefined method `accept' for nil:NilClass

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

这是宝石列表(不是全部):

activemodel (3.2.8)
activerecord (3.2.8)
activerecord-mysql2-adapter (0.0.3)
builder (3.1.3, 3.0.3)
bundler (1.2.1)
mysql2 (0.3.2)

rails (3.2.8)
rails_apps_composer (2.2.10)
railties (3.2.8)
rake (0.9.2.2)
rdoc (3.12)
sqlite3 (1.3.6)
therubyracer (0.10.2)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.10)
twitter-bootstrap-rails (2.1.3)
tzinfo (0.3.33)
uglifier (1.3.0)

我尝试过所有版本的mysql2(从0.2.7到0.3.2)

编辑(数据库文件):

development:
  adapter: mysql2
  database: tripwall
  username: root
  password: pass
  host: localhost
  pool: 5
  timeout: 5000

Sean 和 Mitch 的两个答案都有助于解决这个问题:

  • mysql2 gem 的版本应为 0.3.11 及以上,并且
  • 应从 gemfile 中删除 activerecord-mysql2-adapter。

想要明确的是:

  1. Your gemfile should contain the following line (remove activerecord-mysql2-adapter alone):

    宝石'mysql2'

  2. gem list should output the following line:

    activerecord-mysql2-适配器 (0.0.3)

    mysql2 (0.3.11)

Edit:

当我尝试打开脚手架生成的模型的索引时,我还收到以下错误:

NoMethodError (undefined method `accept' for nil:NilClass):
app/controllers/posts_controller.rb:5:in `index'

我不得不重新启动 Rails 服务器;这解决了问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails mysql2 未定义方法“accept” for nil:NilClass 的相关文章

随机推荐