Anybody know what would cause rake to fail with: rake aborted! undefined method `+'' for nil:NilClass ./rakefile:93 This is on a freshly created rails project, on Windows XP, using MySQL 4.1.9. I can add code to my app and it all seems to work, but I''d like to be able to use the tasks in the rakefile. I did see some older posts about it on this list, but there didn''t seem to be a resolution. Thanks, Kevin
* Kevin McConnell <kevin.mcconnell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> [0210 23:10]:> Anybody know what would cause rake to fail with: > > rake aborted! > undefined method `+'' for nil:NilClass > ./rakefile:93 > > This is on a freshly created rails project, on Windows XP, using MySQL > 4.1.9. > > I can add code to my app and it all seems to work, but I''d like to be > able to use the tasks in the rakefile. > > I did see some older posts about it on this list, but there didn''t seem > to be a resolution.Try a ''rake -t'' , to check what task is going bang. It''s either: a) you have no test database configured in databases.yml. or b) rake is trying to run either the unit tests with an empty test/units directory, or the functional tests with an empty test/functional folder. (sorry I can''t be more specific, I have buggered about with my Rakefile so don''t know what''s on line 93 ). -- ''Everybody I know who is right always agrees with ME.'' -- Rev Lady Mal Rasputin :: Jack of All Trades - Master of Nuns
> Try a ''rake -t'' , to check what task is going bang.It''s "db_structure_dump". I''ve pasted the full output below.> a) you have no test database configured in databases.yml.I do have.> b) rake is trying to run either the unit tests with an empty test/units > directory, or the functional tests with an empty test/functional folder.There are tests there, so it''s not that either :( I''ll try reading into the code to find out exactly what''s happenning, but I was hoping somebody else would''ve see this already. Thanks for the suggestions, Kevin <snip> ** Invoke default (first_time) ** Invoke clone_structure_to_test (first_time) ** Invoke db_structure_dump (first_time) ** Execute db_structure_dump rake aborted! undefined method `+'' for nil:NilClass c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.5.1/lib/active_record/connection_a dapters/mysql_adapter.rb:108:in `structure_dump'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.5.1/lib/active_record/connection_a dapters/mysql_adapter.rb:107:in `inject'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.5.1/lib/active_record/connection_a dapters/mysql_adapter.rb:107:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.5.1/lib/active_record/connection_a dapters/mysql_adapter.rb:107:in `inject'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.5.1/lib/active_record/connection_a dapters/mysql_adapter.rb:107:in `structure_dump'' ./rakefile:93 ./rakefile:93:in `open'' ./rakefile:93 ./rakefile:90:in `call'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:122:in `execute'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:122:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:122:in `execute'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:100:in `invoke'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:99:in `invoke'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:99:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:99:in `invoke'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:99:in `invoke'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:99:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:99:in `invoke'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:1005:in `run'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:1005:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/lib/rake.rb:1005:in `run'' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.4.15/bin/rake:7 c:/ruby/bin/rake:19:in `load'' c:/ruby/bin/rake:19
Following up, it seems that SHOW CREATE TABLE is not returning a column name in its results. And it looks like the code is expecting a column name of "Create Table". Could this be to do with differring MySQL versions? The following change makes the task run OK : from: def structure_dump select_all("SHOW TABLES").inject("") do |structure, table| structure += select_one("SHOW CREATE TABLE {table.to_a.first.last}")["Create Table"] + ";\n\n" end end to: def structure_dump select_all("SHOW TABLES").inject("") do |structure, table| structure += select_one("SHOW CREATE TABLE #{table.to_a.first.last}").values[0] + ";\n\n" end end I have zero MySQL experience, so perhaps this will all make more sense to somebody else :) Cheers, Kevin
One reason for the rake task "clone_structure_to_test" to fail against mysql (via mysql_adapter''s structure_dump()) would be if you have a view defined in your schema. There''s a patch - see ticket #3782: "[PATCH] mysql5 + views crashes unit testing" at http://dev.rubyonrails.org/ticket/3782