Migration Problem - wrong number of arguments

Greetings all, I’ve been having trouble getting migration to work as I
understand it should.

Basically what I am doing is following the example (sort of) for making
a table that will store data that will be used to create a tree using
"acts_as_tree: – shown on page 104 of the O’reily Rails Cookbook.

When I run “rake db:migrate” the code below successfully creates a table
named “tabs” as required – so I know I have a good connection to the
database with necessary permissions. However, the rake task throws an
error when it gets to the part where I want it to add some initial
default data to the table – or at least I think this is where the
problem is.

Below is part of the trace and error message thrown by rake. You’ll
note the last line references: “001_create_database.rb:15” – which is
the same line number where my migration code trys to add records to the
table.

C:\rails\tabs>rake db:migrate --trace
(in C:/rails/tabs)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
ActionController called
** Execute db:migrate
== CreateDatabase: migrating

– create_table(:tabs, {:force=>true})
-> 0.1720s
rake aborted!
wrong number of arguments (1 for 0)
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:449:in
initialize' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:449:innew’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:449:in
create' ./db/migrate//001_create_database.rb:15:inreal_up’

Here is my code:

class CreateDatabase < ActiveRecord::Migration

def self.up
# Create a Tabs table
create_table :tabs, :force => true do |t|
t.column :parent_id, :integer
t.column :name, :string, :limit => 36
t.column :c_controller, :string
t.column :c_action, :string
t.column :c_id, :string
end

# Insert default data into the Tabs table for testing and

development
Tab.create :parent_id => 0, :name => ‘Home’, :c_controller =>
‘page’, :c_action => ‘view’, :c_id => ‘0’
Tab.create :parent_id => 0, :name => ‘About’, :c_controller =>
‘page’, :c_action => ‘view’, :c_id => ‘1’
Tab.create :parent_id => 2, :name => ‘Team’, :c_controller =>
‘page’, :c_action => ‘view’, :c_id => ‘2’
Tab.create :parent_id => 2, :name => ‘Contact’, :c_controller =>
‘page’, :c_action => ‘view’, :c_id => ‘3’
Tab.create :parent_id => 0, :name => ‘Products’, :c_controller =>
‘page’, :c_action => ‘view’, :c_id => ‘4’

end

def self.down
drop_table :tabs
end

end

On 13-Feb-07, at 4:38 PM, Doug M. wrote:

  t.column :c_controller, :string
  t.column :c_action, :string
  t.column :c_id, :string
end

# Insert default data into the Tabs table for testing and

development
Tab.create :parent_id => 0, :name => ‘Home’, :c_controller =>
‘page’, :c_action => ‘view’, :c_id => ‘0’

Doug, it’s my understanding that rails needs to be prodded to
understand your new model definition.

Prodding can be done like this:

class CreateDatabase < ActiveRecord::Migration
class Tab < ActiveRecord::Base; end

#do your create table as usual, then…

Tab.reset_column_information #tell the model to check out it’s
current/new definition

#then do your Tab.create statements

I use the above technique, and it works like a charm.

cheers,
Jodi

Jodi S. wrote:

On 13-Feb-07, at 4:38 PM, Doug M. wrote:

  t.column :c_controller, :string
  t.column :c_action, :string
  t.column :c_id, :string
end

# Insert default data into the Tabs table for testing and

development
Tab.create :parent_id => 0, :name => ‘Home’, :c_controller =>
‘page’, :c_action => ‘view’, :c_id => ‘0’

Doug, it’s my understanding that rails needs to be prodded to
understand your new model definition.

Prodding can be done like this:

class CreateDatabase < ActiveRecord::Migration
class Tab < ActiveRecord::Base; end

#do your create table as usual, then…

Tab.reset_column_information #tell the model to check out it’s
current/new definition

#then do your Tab.create statements

I use the above technique, and it works like a charm.

cheers,
Jodi

Jodi – first, thanks for the quick reply! Your instructions worked
like a champ. I printed it out and put a copy in my rails book.

Doug