Home>

I would like to redevelop and study a project cloned from github in a local environment.
At that time, in order to build the database, it is necessary to refer to the migration file and create the database, but when I executed that command, I got an error like this.

$rails db: migrate
rails aborted!
NoMethodError: Cannot load database configuration:
undefined method ʻeach'for "u # MySQL. Versions 5.1.10 and up are supported.": String
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/application/configuration.rb:175:in `database_configuration'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.2/lib/active_record/railtie.rb:39:in `block (3 levels) in<class: Railtie>'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/command.rb:48:in ʻinvoke'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/commands.rb:18:in `<main>'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:in `block in require'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:in `require'
/ Users/user/rails_workspace/tasklist/bin/rails: 9: in `<top (required)>'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
/ Users/user/rails_workspace/tasklist/bin/spring: 15: in `<top (required)>'
bin/rails: 3: in `load'
bin/rails: 3: in `<main>'
Caused by:
NoMethodError: undefined method ʻeach'for "u # MySQL. Versions 5.1.10 and up are supported.": String
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/application/configuration.rb:175:in `database_configuration'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.4.2/lib/active_record/railtie.rb:39:in `block (3 levels) in<class: Railtie>'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/command.rb:48:in ʻinvoke'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.2/lib/rails/commands.rb:18:in `<main>'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:in `block in require'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.2/lib/active_support/dependencies.rb:291:in `require'
/ Users/user/rails_workspace/tasklist/bin/rails: 9: in `<top (required)>'/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
/Users/user/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
/Users/usera/rails_workspace/tasklist/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
/ Users/user/rails_workspace/tasklist/bin/spring: 15: in `<top (required)>'
bin/rails: 3: in `load'
bin/rails: 3: in `<main>'
Tasks: TOP =>db: migrate =>db: load_config
(See full trace by running task with --trace)


The version of what i am using.

  • Rails 5.2.4.2
  • mysql Ver 8.0.21 for osx10.15 on x86_64 (Homebrew)
  • ruby 2.6.6 (set by /Users/user/rails_workspace/tasklist/.ruby-version)

I've researched various things, but I can't find a solution ...
Thank you.

Also, I have no idea how to read the error, so I would appreciate it if you could teach me as well.

  • Answer # 1

    In typo, it seems that unrecognized characters were left as they were outside the comment, and when I removed them, they ran without problems.
    I intended to confirm the mistake, but I'm sorry.

    Actual file

    u # MySQL. Versions 5.1.10 and up are supported.
    #
    #Install the MySQL driver
    # gem install mysql2
    #
    #Ensure the MySQL gem is defined in your Gemfile
    # gem'mysql2'
    #
    # And be sure to use new-style password hashing:
    # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
    #
    default:&default
      adapter: mysql2
      encoding: utf8
      pool: 5
      username:<username>
      password:<password>
      socket: /tmp/mysql.sock
    development:
    <<: * default
      database:<databasename>
    #Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test: test:
    <<: * default
      database: tasklist_test
    # As with config/secrets.yml, you never want to store sensitive information,
    # like your database password, in your source code. If your source code is
    #ever seen by anyone, they now have access to your database.
    #
    # Instead, provide the password as a unix environment variable when you boot
    # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
    # for a full rundown on how to provide these environment variables in a
    #production deployment.
    #
    # On Heroku and other platform providers, you may have a full connection URL
    #available as an environment variable. For example:
    #
    # DATABASE_URL = "mysql2: // myuser: mypass @ localhost/somedatabase"
    #
    #You can use this database configuration with:
    #
    #production:
    # url:<% = ENV ['DATABASE_URL']%>
    #
    production:
      adapter: postgresql
      encoding: unicode
      pool: 5
      database: message-board_production
      username: message-board
      password:<% = ENV ['MESSAGE-BOARD_DATABASE_PASSWORD']%>

    Since I wrote it in vim, the color didn't change and I didn't notice it at all. Thank you very much.
    (It's the top "u" !! lol)