运行rake任务时,nil:NilClass的未定义方法“ accept”

时间:2018-06-29 04:49:54

标签: ruby-on-rails ruby ruby-on-rails-3.2 mysql2

我有一个Ruby-on-Rails和MyQSL Server的mysql2 (0.5.1)(3.2.2)应用程序

  

mysql --version

mysql --version Ver 8.0.11(适用于x86_64(自制))上的osx10.13。

当我执行bundle exec rake db:setup时,数据库被创建。

当我尝试bundle exec rake db:migrate时,会发生此故障:

bundle exec rake db:migrate --trace                                                                           
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
NoMethodError: undefined method `accept' for nil:NilClass
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/database_statements.rb:38:in `select_values'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:587:in `get_all_versions'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:745:in `migrated'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:668:in `current_version'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:685:in `block in migrate'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:685:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:685:in `detect'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:685:in `migrate'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:570:in `up'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/migration.rb:551:in `migrate'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:193:in `block (2 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:424:in `exec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:27:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:18:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `<main>'
Tasks: TOP => db:migrate

我没有找到任何解决方案。 我必须安装gem "activerecord-mysql2-adapter"才能运行它。 没有那个宝石,它会抛出这个:

LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.5.1. Make sure all dependencies are added to Gemfile.)

当我运行旧版本(mysql2 0.3.2.1的原始版本)时,发生了这种情况: (由于此失败,我进行了更新)

gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'                                                5 ↵  2.3.3    RSpec: 128.09%
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/ext/mysql2
/Users/janjezek/.rbenv/versions/2.3.3/bin/ruby -r ./siteconf20180629-41801-6cf56s.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting rpath to /usr/local/Cellar/mysql/8.0.11/lib
-----
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:



    /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-17/2.3.0-static/mysql2-0.3.21/mkmf.log

    current directory: /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/ext/mysql2
    make "DESTDIR=" clean

    current directory: /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/ext/mysql2
    make "DESTDIR="
    compiling infile.c
    compiling client.c
    client.c:439:3: error: use of undeclared identifier 'my_bool'
      my_bool res = mysql_read_query_result(client);
      ^
    client.c:441:19: error: use of undeclared identifier 'res'
      return (void *)(res == 0 ? Qtrue : Qfalse);
                      ^
    client.c:762:3: error: use of undeclared identifier 'my_bool'
      my_bool boolval;
      ^
    client.c:793:7: error: use of undeclared identifier 'boolval'
          boolval = (value == Qfalse ? 0 : 1);
          ^
    client.c:794:17: error: use of undeclared identifier 'boolval'
          retval = &boolval;
                    ^
    client.c:797:10: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
        case MYSQL_SECURE_AUTH:
             ^~~~~~~~~~~~~~~~~
             MYSQL_DEFAULT_AUTH
    /usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
      MYSQL_DEFAULT_AUTH,
      ^
    client.c:798:7: error: use of undeclared identifier 'boolval'
          boolval = (value == Qfalse ? 0 : 1);
          ^
    client.c:799:17: error: use of undeclared identifier 'boolval'
          retval = &boolval;
                    ^
    client.c:830:38: error: use of undeclared identifier 'boolval'
            wrapper->reconnect_enabled = boolval;
                                         ^
    client.c:1185:38: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
      return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
                                         ^~~~~~~~~~~~~~~~~
                                         MYSQL_DEFAULT_AUTH
    /usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
      MYSQL_DEFAULT_AUTH,
      ^
    10 errors generated.
    make: *** [client.o] Error 1

    make failed, exit code 2

    Gem files will remain installed in /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21 for inspection.
    Results logged to /Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-17/2.3.0-static/mysql2-0.3.21/gem_make.out

(顺便说一句:我可以连接到mysql -u root -p,并且创建的数据库就在其中。)

还有其他建议吗?

完成:

database.yml

development:
  adapter: mysql2
  host: 127.0.0.1
  port: 3306
  database: mydb_development
  username: root
  password: root

编辑:

没有mysqladapter gem:

rake aborted!
LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.10. Make sure all dependencies are added to Gemfile.)
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `block in require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:29:in `spec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:101:in `create_database'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:424:in `exec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:27:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:18:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `<main>'
Gem::LoadError: can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.10. Make sure all dependencies are added to Gemfile.
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `block in require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:29:in `spec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:101:in `create_database'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-3.2.22/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/rake:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:424:in `exec'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:27:in `dispatch'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/cli.rb:18:in `start'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Users/janjezek/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `load'
/Users/janjezek/.rbenv/versions/2.3.3/bin/bundle:22:in `<main>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create

3 个答案:

答案 0 :(得分:2)

您需要安装mysql2个gem或任何其他替代品。具有本地扩展名的宝石 有时需要与它们绑定的库的 development 库进行编译。那说:

# gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'
Building native extensions.  This could take a while...
  ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

-表示您需要安装 libmysqlclient-dev 软件包(Ubuntu,在其他操作系统上,请阅读相应的文档。)

要在Ubuntu上安装此软件包,请运行sudo apt-get install libmysqlclient-dev

答案 1 :(得分:1)

尝试摆脱宝石activerecord-mysql2-adapter,然后安装宝石mysql2,它应该可以工作

答案 2 :(得分:1)

TL; DR;

这是针对Ruby on Rails 3.2.22

我的Mac上具有 mysql 版本8.x。 我也安装了5.6。 我发现该应用程序的原始mysql服务器为5.7

所以我安装了mysql Version 5.7并成功了!

清理

宝石文件:

gem 'mysql2', '~> 0.3.21' # in Gemfile


brew uninstall mysql mysql@5.6
brew install mysql@5.7

从任何/Users/YOURNAME/.rbenv/versions/2.3.3/lib/ruby/gemsmysql东西中清理activerecord-mysql2-adapter文件夹。

gem uninstall activerecord-mysql2-adapter # each version
gem uninstall mysql2 # each version
bundle update mysql2
bundle install

就是这样。谢谢你们指导我