Rake db:migrate "undefined method `default'" error

Hi all,

Just starting with Rails and working through the early chapters of the
Pragmatic Programmers Agile Development with Rails book (2nd addition).
When doing a “rake db:migrate” to add a column to a table I get this:
undefined method `default’ for
#ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb7517ec8

Any ideas?

thanks,
David

PS: Here’s the full output with the trace parameter:

[email protected]:/share/David/radrails/workspace/depot$ rake db:migrate
–trace
(in /share/David/radrails/workspace/depot)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddPrice: migrating

– default()
rake aborted!
undefined method default' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb74f240c> /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:275:insend’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:275:in
method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:259:insay_with_time’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:259:insay_with_time’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:273:in
method_missing' ./db/migrate//002_add_price.rb:3:inreal_up’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:212:in
migrate' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:212:in
migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:335:inmigrate’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:330:in
migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:297:inup’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/migration.rb:288:in
migrate' /usr/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/tasks/databases.rake:4 /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:inexecute’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:ininvoke’
/usr/lib/ruby/1.8/thread.rb:135:in synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:ininvoke’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in run' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:inrun’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
/usr/bin/rake:16

Could you post the migration code?

Common problems include using a reserved word (mysql or ruby.

Not sure, but default sounds like a common one.

That was it, I forgot the colon before the “default”:

class AddPrice < ActiveRecord::Migration
def self.up
add_column :products, :price, :decimal, :precision => 8, :scale =>
2, default => 0
end

def self.down
remove_column :products, :price
end
end

I’m all good now, thanks David, much appreciated.

Just use rake 0.8.7
Uninstall rake 0.9.0
gem uninstall rake -v 0.9.0
And in your Gemfile:
gem ‘rake’, ‘0.8.7’
Don’t forget: bundle install

Alexander,

When I tried that uninstall, I got:

While executing gem … (Gem::InstallError)
cannot uninstall, check gem list -d rake

On Jul 23, 9:54pm, “Chris v. N.” [email protected] wrote:

Alexander,

When I tried that uninstall, I got:

If you’re using bundler you don’t need to uninstall rake - updating
the version required in the gemfile (and running bundle install if you
didn’t have 0.8.7 around) should be enough

Fred

Sorry guys, I am new at RoR and have the above error as I try to run
rake db:migrate. Could anyone help.

With --trace I get

rake db:migrate --trace
rake aborted!
undefined method task' for #<Harpers::Application:0x9277438> /home/student/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.7/lib/rails/application.rb:215:ininitialize_tasks’
/home/student/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.7/lib/rails/application.rb:139:in
load_tasks' /home/student/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.7/lib/rails/application.rb:77:inmethod_missing’
/home/student/home/harpers/Rakefile:7:in <top (required)>' /home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/rake_module.rb:25:inload’
/home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in
load_rakefile' /home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:495:inraw_load_rakefile’
/home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:78:in
block in load_rakefile' /home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:129:instandard_exception_handling’
/home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:77:in
load_rakefile' /home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:61:inblock in run’
/home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:129:in
standard_exception_handling' /home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:59:inrun’
/home/student/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/bin/rake:31:in
<top (required)>' /home/student/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:inload’
/home/student/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs