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:in
new’
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:in
real_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