Topic: undefined method `each' for #<Mysql:0x4841af8>

Hey everyone (sorry for posting this in the wrong forum initially),

I'm just getting setup now that I can deploy, and needed to make and preview a change on my dev system.  The problem is that I had a severe data-loss, and had to reinstall everything.  So my exact environment in which my Rails app got into working condition is permanently lost.  And now it becomes a more serious problem.  hmm

I am working on a Mongrel/MySQL/Windows machine for development, and deploying to Dreamhost.

So how'd I get the error?  I just "rake db:migrate" or "rake db:schema:load" and MySQL goes nuclear.  Since there's no description of why this is happening, and this is my first Rails project, I'm really stumped at how to fix this.

This was working, and I'm sure will work on the server, but until I can regain my development environment I cannot support it.

Maybe the MySQL version is buggy?  Or, Rails 2.2.2 isn't compatible with ... 2.2.1?  I'll provide any info you guys need to help me out, because I really want to continue using Rails.

So here's my stuff:
[code=gem list --local]*** LOCAL GEMS ***
actionmailer (2.2.2)
actionpack (2.2.2)
activerecord (2.2.2)
activeresource (2.2.2)
activesupport (2.2.2)
BlueCloth (1.0.0)
capistrano (2.5.5)
cgi_multipart_eof_fix (2.5.0)
diff-lcs (1.1.2)
gem_plugin (0.2.3)
grit (1.0.1)
haml (2.0.9, 2.0.8, 2.0.7)
highline (1.5.0)
maruku (0.5.9)
mime-types (1.16, 1.15)
mongrel (1.1.5)
mysql (2.7.3)
net-scp (1.0.2)
net-sftp (2.0.2)
net-ssh (2.0.11)
net-ssh-gateway (1.0.1)
polyglot (0.2.5, 0.2.4)
pony (0.3)
rack (0.9.1)
rails (2.2.2)
rake (0.8.4, 0.8.3)
RedCloth (4.1.9, 4.1.1)
rubypants (0.2.0)
schacon-git (1.0.7)
sequel (2.11.0, 2.10.0)
sinatra (0.9.1, 0.9.0.4)
syntax (1.0.0)
tmail (1.2.3.1)
treetop (1.2.4)
WikiCreole (0.1.3)[/code]


Stack Trace of "rake db:migrate":
[code=rake:db:migrate]** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  RenamePasswordToHashed: migrating
=========================================
-- rename_column(:users, :password, :hashed_password)
rake aborted!
An error has occurred, all later migrations canceled:

undefined method `each' for #<Mysql:0x4841af8>
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connec
tion_adapters/mysql_adapter.rb:440:in `columns'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connec
tion_adapters/mysql_adapter.rb:485:in `rename_column'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:346:in `send'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:346:in `method_missing'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:326:in `say_with_time'
C:/Utils/Ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:326:in `say_with_time'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:342:in `method_missing'
./db/migrate//20081121194833_rename_password_to_hashed.rb:3:in
`up_without_bench
marks'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:280:in `send'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:280:in `migrate'
C:/Utils/Ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:280:in `migrate'
(__DELEGATION__):2:in `__send__'
(__DELEGATION__):2:in `migrate'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:480:in `migrate'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:556:in `call'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:556:in `ddl_transaction'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:479:in `migrate'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:466:in `each'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:466:in `migrate'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:394:in `up'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:377:in `migrate'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:111
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in
`call'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in
`execute'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in
`each'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in
`execute'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in
`invoke_with_
call_chain'
C:/Utils/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in
`invoke_with_
call_chain'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in
`invoke'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2027:in
`invoke_task
'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
`top_level'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
`each'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
`top_level'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in
`standard_ex
ception_handling'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in
`top_level'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in
`run'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in
`standard_ex
ception_handling'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in
`run'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake:31
C:/Utils/Ruby/bin/rake:19:in `load'
C:/Utils/Ruby/bin/rake:19[/code]

Re: undefined method `each' for #<Mysql:0x4841af8>

You should post the migration that is causing the error to be thrown.

Re: undefined method `each' for #<Mysql:0x4841af8>

Ready to squint in wonder at the complexity?  This is exactly why I can't figure it out.  As I said it was working just a short while ago, but since I had to rebuild my OS and utilities from the ground up (ack) it hasn't worked right.

class RenamePasswordToHashed < ActiveRecord::Migration
  def self.up
    rename_column(:users, :password, :hashed_password)
  end

  def self.down
    rename_column(:users, :hashed_password, :password)
  end
end

Last edited by RobertK (2009-03-10 10:39:30)

Re: undefined method `each' for #<Mysql:0x4841af8>

rake db:schema:load is the way to go, what is the error message provided?

Re: undefined method `each' for #<Mysql:0x4841af8>

As requested.  But so far, it's the same error as far as I can tell in another place.

rake db:schema:load

** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:schema:load
-- create_table("articles", {:force=>true})
   -> 0.0470s
-- create_table("pages", {:force=>true})
rake aborted!
undefined method `each' for #<Mysql:0x483d4d0>
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connec
tion_adapters/mysql_adapter.rb:414:in `tables'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connec
tion_adapters/abstract/schema_statements.rb:24:in `table_exists?'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connec
tion_adapters/abstract/schema_statements.rb:106:in `create_table'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connec
tion_adapters/mysql_adapter.rb:445:in `create_table'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:346:in `send'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:346:in `method_missing'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:326:in `say_with_time'
C:/Utils/Ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:326:in `say_with_time'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/migrat
ion.rb:342:in `method_missing'
C:/Programming/church/db/schema.rb:23
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/schema
.rb:43:in `instance_eval'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/schema
.rb:43:in `define'
C:/Programming/church/db/schema.rb:12
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/depe
ndencies.rb:142:in `load_without_new_constant_marking'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/depe
ndencies.rb:142:in `load'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/depe
ndencies.rb:521:in `new_constants_in'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/depe
ndencies.rb:142:in `load'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:253
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `call'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `execute'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `each'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `execute'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in `invoke_with_
call_chain'
C:/Utils/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in `invoke_with_
call_chain'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in `invoke'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2027:in `invoke_task
'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `each'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in `standard_ex
ception_handling'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in `top_level'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in `run'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in `standard_ex
ception_handling'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in `run'
C:/Utils/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake:31
C:/Utils/Ruby/bin/rake:19:in `load'
C:/Utils/Ruby/bin/rake:19

Re: undefined method `each' for #<Mysql:0x4841af8>

What version of MySQL are you running?

Rob Anderton
TheWebFellas

Re: undefined method `each' for #<Mysql:0x4841af8>

I'm using MySQL 5.1.30; I use XAMPP to set my server up with MySQL, etc.

Edit: If it means anything, not even Sequel is working right as an ORM either.  I'm suspecting that it's something to do with my PC.

Last edited by RobertK (2009-03-10 18:42:02)

Re: undefined method `each' for #<Mysql:0x4841af8>

You may have already seen these, but if not they suggest copying an older MySQL dll for Ruby to use as apparently the MySQL 5.1 dll doesn't play nicely with the MySQL gem...

RubyForum thread
Thread with more info
Link to older DLL

No idea if it'll help, but might be worth a try big_smile

Rob Anderton
TheWebFellas

Re: undefined method `each' for #<Mysql:0x4841af8>

Well, lets see if that DLL plays nicely, then.  And no I hadn't seen the thread--I hadn't a clue what to search for to find a solution.

It works!  Thanks a bunch Rob, you've pretty much snatched my Rails development urge from the pit of doom.

Re: undefined method `each' for #<Mysql:0x4841af8>

rob-twf wrote:

You may have already seen these, but if not they suggest copying an older MySQL dll for Ruby to use as apparently the MySQL 5.1 dll doesn't play nicely with the MySQL gem...

RubyForum thread
Thread with more info
Link to older DLL

No idea if it'll help, but might be worth a try big_smile

This completely worked for me as well.  I went back to MYSQL 5.0 and used the older libmySQL.dll and it worked like a charm.

11

Re: undefined method `each' for #<Mysql:0x4841af8>

Well add me to this list - I have wasted 3 days trying to figure out why a working app on one machine would not work on another.  I knew the other later setup had 5.1 & as soon as I saw this thread realized it was going to be incompatibility between MySql versions.

Thanks Sun & MySQL, I love you all  sad

DSJM

Re: undefined method `each' for #<Mysql:0x4841af8>

Thanks very much, Rob Anderton!  This worked!! I spent a long time trying to figure out what went wrong.  Also, as icing on the cake, thanks for posting a link right to the proper dll. 
I copied the file libmySQL.dll to my ruby\bin folder, and now everything works great!

rob-twf wrote:

You may have already seen these, but if not they suggest copying an older MySQL dll for Ruby to use as apparently the MySQL 5.1 dll doesn't play nicely with the MySQL gem...

RubyForum thread
Thread with more info
Link to older DLL

No idea if it'll help, but might be worth a try big_smile

Re: undefined method `each' for #<Mysql:0x4841af8>

Feel free to send tokens of appreciation big_smile

Seriously though, glad to help!

Rob Anderton
TheWebFellas