Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

rake db:create problem in rails3 with mysql2

#5502

Here is the trace of the error

rake db:create --trace
(in /home/radu/projects/r30) Invoke db:create (first_time) Invoke db:load_config (first_time) Invoke rails_env (first_time) Execute rails_env Execute db:load_config Execute db:create rake aborted! undefined method errno' for #<Mysql2::Error:0xb70e1ebc> /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/railties/databases.rake:71:increate_database' /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/railties/databases.rake:33 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in call' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:inexecute' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:inexecute' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:insynchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:ininvoke' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in invoke_task' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in each' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:intop_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:intop_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:inload' /usr/bin/rake:19


I addressed the problem to the mysql2 gem creators on github and they told me it is rails3 related:

This is actually a bug in the Rails 3 database rake tasks at: http://github.com/rails/rails/blob/master/activerecord/lib/active_r...

Mysql2::Error has a method called error_number whereas the old mysql gem's error class has errno - this should be an easy fix but would you mind opening a bug in the Rails 3 tracker?

Reported by rdinca · August 30th, 2010 @ 08:44 PM

State: resolved
Milestone: 3.0.2
Assigned to: nobody
Importance: Medium

Activity

  1. Neeraj Singh
    Neeraj Singh
    • State changed from new to open
    • Tag set to rails 3, activerecord
    • Importance changed from to Low

    Attached is a code patch. Can you try and see if it fixes your problem.

    August 30th, 2010 @ 09:11 PM

  2. Marjan Krekoten'
    Marjan Krekoten'

    I have another patch which addresses this issue and also nonexistent Mysql::Error#error method. It also deals with situation when we use old mysql gem and 'uninitialized constant Mysql2' message gets raised.

    August 30th, 2010 @ 10:48 PM

  3. rdinca
    rdinca

    I can confirm Marjan Krekoten' s patch is working for me ( haven't tried the other one ), but it is rather unpleasant having to modifing database.rake... perhaps the patch should be included into rails right away, not forcing mysql users to hack into activerecord files.

    August 31st, 2010 @ 04:14 PM

  4. Marjan Krekoten'
    Marjan Krekoten'
    • Assigned user set to José Valim

    September 1st, 2010 @ 07:02 AM

  5. José Valim
    José Valim
    • Milestone cleared.
    • Assigned user changed from José Valim to Brian Lopez
    • Importance changed from Low to Medium

    Brian, do you think we can make MySQL2 error have the same API as MySQL one and do a small release?

    September 1st, 2010 @ 08:26 AM

  6. Marjan Krekoten'
    Marjan Krekoten'

    I agree with José Valim. It probably would be better to do somthing like this

    class Mysql2::Error
        # ...
        alias_method :errno, :error_number
        alias_method :error, :message
    end
    

    But following is still needed, because it avoids 'uninitialized constant Mysql2' when we use mysql instead of mysql2:

    error_class = "#{config['adapter'].capitalize}::Error".constantize
    

    I can edit this patch and also make patch for mysql2 if José Valim and Brian Lopez agree with this.

    September 1st, 2010 @ 09:00 AM

  7. Brian Lopez
  8. Marjan Krekoten'
    Marjan Krekoten'

    Cool! I've updated patch to fix 'uninitialized constant Mysql2'. But this problem will go away completely with new release of mysql2 gem.

    September 1st, 2010 @ 08:06 PM

  9. Brian Lopez
    Brian Lopez

    I'll try and push 0.2.4 by tonight

    September 1st, 2010 @ 08:07 PM

  10. jw
    jw

    Is there a non hacky way for a rails mortal like me to resolve this problem? I have updated to rails 3 today and have since not been able to do any development. Thanks.

    September 2nd, 2010 @ 04:58 PM

  11. Bison
    Bison

    Any progress on this issue? I'm new to Rails and (like jw) this has held me up for almost a week now. Is there an easy workaround? Thanks.

    September 8th, 2010 @ 08:00 PM

  12. Marjan Krekoten'
    Marjan Krekoten'

    Well we need to wait for next release of mysql2. It will introduce compatibility with mysql gem. Or you can point your Gemfile to mysql2 git repo.

    September 8th, 2010 @ 09:29 PM

  13. Marjan Krekoten'
    Marjan Krekoten'

    mysql2 v0.2.4 released with mysql compatibility fix. So I think we should update development and generated Gemfile to use >= 0.2.4. I've attached a patch.

    September 19th, 2010 @ 09:03 PM

  14. Jeremy Kemper
  15. Ryan Bigg
    Ryan Bigg
    • Tag changed from rails 3, sheepskin boots, activerecord to activerecord rails 3

    Automatic cleanup of spam.

    October 16th, 2010 @ 02:38 AM

  16. Rohit Arondekar
    Rohit Arondekar

    Currently the Gemfile uses 0.2.6. The rest hasn't been applied yet. Was the issue resolved?

    October 25th, 2010 @ 09:43 AM

  17. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    November 1st, 2010 @ 05:06 PM

  18. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to resolved

    I have talked with Brian and this is resolved now. If somebody has still some kind of trouble with this, please comment here and I will reopen it.

    November 11th, 2010 @ 03:45 AM

  19. John
    John

    Hi, I'm running rails 3.0.3, ruby 1.9.2p0, mysql 5.1.53, and when i run rake db:create I get the following:

    ** Invoke db:create (first_time)
    ** Invoke db:load_config (first_time)
    ** Invoke rails_env (first_time)
    ** Execute rails_env
    ** Execute db:load_config
    ** Execute db:create
    rake aborted!
    uninitialized constant Mysql
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rspec-expectations-2.0.1/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:64:in `rescue in create_database'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:39:in `create_database'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:33:in `block (2 levels) in <top (required)>'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in `call'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in `each'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'
    /Users/John/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `load'
    /Users/John/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `<main>'
    

    My gems are:

    *** LOCAL GEMS ***
    
    abstract (1.0.0)
    actionmailer (3.0.3, 3.0.0)
    actionpack (3.0.3, 3.0.0)
    activemodel (3.0.3, 3.0.0)
    activerecord (3.0.3, 3.0.0)
    activeresource (3.0.3, 3.0.0)
    activesupport (3.0.3, 3.0.0)
    addressable (2.2.2)
    arel (2.0.6, 1.0.1)
    bcrypt-ruby (2.1.2)
    builder (2.1.2)
    bundler (1.0.2)
    cgi_multipart_eof_fix (2.5.0)
    configuration (1.2.0, 1.1.0)
    cucumber (0.10.0, 0.9.3)
    cucumber-rails (0.3.2)
    daemons (1.1.0, 1.0.10)
    database_cleaner (0.6.0)
    devise (1.1.5, 1.1.3)
    diff-lcs (1.1.2)
    erubis (2.6.6)
    faraday (0.5.3)
    fastthread (1.0.7)
    gem_plugin (0.2.3)
    gherkin (2.3.2, 2.2.9)
    i18n (0.5.0, 0.4.1)
    jasmine (1.0.1.1, 1.0.1)
    json (1.4.6)
    json_pure (1.4.6)
    launchy (0.3.7)
    mail (2.2.12, 2.2.7)
    mime-types (1.16)
    mongrel (1.2.0.pre2)
    multi_json (0.0.5)
    multipart-post (1.0.1)
    mysql2 (0.2.6)
    net-ldap (0.1.1)
    nokogiri (1.4.4, 1.4.3.1)
    oa-basic (0.1.6)
    oa-core (0.1.6)
    oa-enterprise (0.1.6)
    oa-oauth (0.1.6)
    oa-openid (0.1.6)
    oauth (0.4.4)
    oauth2 (0.1.0)
    omniauth (0.1.6)
    pg (0.9.0)
    polyglot (0.3.1)
    pyu-ruby-sasl (0.0.3.2)
    rack (1.2.1)
    rack-mount (0.6.13)
    rack-openid (1.2.0)
    rack-test (0.5.6)
    rails (3.0.3, 3.0.0)
    railties (3.0.3, 3.0.0)
    rake (0.8.7)
    rest-client (1.6.1)
    rspec (2.0.1)
    rspec-core (2.0.1)
    rspec-expectations (2.0.1)
    rspec-mocks (2.0.1)
    rspec-rails (2.0.1)
    ruby-openid (2.1.8)
    ruby-openid-apps-discovery (1.2.0)
    rubyntlm (0.1.1)
    selenium-client (1.2.18)
    selenium-rc (2.2.4)
    spork (0.8.4)
    term-ansicolor (1.0.5)
    thor (0.14.6, 0.14.3)
    treetop (1.4.9, 1.4.8)
    tzinfo (0.3.23)
    warden (1.0.2, 0.10.7)
    webrat (0.7.2)
    

    December 12th, 2010 @ 05:30 PM

  20. mehstg
    mehstg

    I am having the same issue. Any ideas guys?

    root@localhost:/var/ruby/testapp# rake db:create --trace
    (in /var/ruby/testapp) Invoke db:create (first_time) Invoke db:load_config (first_time) Invoke rails_env (first_time) Execute rails_env Execute db:load_config Execute db:create rake aborted!
    uninitialized constant Mysql2
    /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:64:in create_database' /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:33 /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun' /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:in load' /usr/bin/rake:19

    December 29th, 2010 @ 12:57 PM

  21. mehstg
    mehstg

    Hi guys

    I am having the same issue at the moment. I am running Rails 3.0.3

    Local Gems:

     LOCAL GEMS 


    abstract (1.0.0) actionmailer (3.0.3) actionpack (3.0.3) activemodel (3.0.3) activerecord (3.0.3) activeresource (3.0.3) activesupport (3.0.3) arel (2.0.6) builder (2.1.2) bundler (1.0.7) columnize (0.3.2) erubis (2.6.6) i18n (0.5.0) linecache (0.43) mail (2.2.13) mime-types (1.16) mysql (2.8.1) mysql2 (0.2.6) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.13) rack-test (0.5.6) rails (3.0.3) railties (3.0.3) rake (0.8.7) ruby-debug (0.10.4) ruby-debug-base (0.10.4) ruby-debug-ide (0.4.16) sqlite3-ruby (1.3.2) SystemTimer (1.2.1) thor (0.14.6) treetop (1.4.9) tzinfo (0.3.23)

    Database config:

    development:
      adapter: mysql2
      encoding: utf8
      database: testapp_development
      pool: 5
      username: root
      password: tax1Rank
      socket: /tmp/mysql.sock

    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: adapter: mysql2 encoding: utf8 database: testapp_test pool: 5 username: root password: tax1Rank socket: /tmp/mysql.sock
    production: adapter: mysql2 encoding: utf8 database: testapp_production pool: 5 username: root password: tax1Rank socket: /tmp/mysql.sock

    Rake with trace:

    (in /var/ruby/testapp)
     Invoke db:create (first_time)
     Invoke db:load_config (first_time)
     Invoke rails_env (first_time)
     Execute rails_env
     Execute db:load_config
     Execute db:create
    rake aborted!
    uninitialized constant Mysql2
    /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:64:in create_database'
    /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/railties/databases.rake:33
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain'
    /usr/lib/ruby/1.8/monitor.rb:242:in synchronize'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun'
    /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
    /usr/bin/rake:19:in load'
    /usr/bin/rake:19</code>
    </pre>
    

    December 29th, 2010 @ 01:05 PM

  22. Marjan Krekoten'
  23. Goksel
    Goksel
    • Assigned user cleared.

    It seems like a Mysql Version Problem. Try uninstalling MYSQL 5.5 if you have this version and install MYSQL 5.1

    January 18th, 2011 @ 01:35 AM

  24. Goksel