Weird error when running migration

I’m having some troubles running what should be a simple migration yet
I’m
getting the error:

rake aborted!
wrong number of arguments (1 for 0)

Here is my migration (the up() method):

initial permissions

Permission.create :name => ‘NEWS_VIEW’
Permission.create :name => ‘NEWS_CREATE’
Permission.create :name => ‘NEWS_EDIT’
Permission.create :name => ‘NEWS_DELETE’
Permission.create :name => ‘NEWS_CATEGORY_CREATE’
Permission.create :name => ‘NEWS_CATEGORY_EDIT’
Permission.create :name => ‘NEWS_CATEGORY_DELETE’
Permission.create :name => ‘NEWS_POST_COMMENT’
Permission.create :name => ‘NEWS_DELETE_COMMENT’
Permission.create :name => ‘KB_VIEW’
Permission.create :name => ‘KB_CATEGORY_CREATE’
Permission.create :name => ‘KB_CATEGORY_EDIT’
Permission.create :name => ‘KB_CATEGORY_DELETE’
Permission.create :name => ‘KB_ARTICLE_CREATE’
Permission.create :name => ‘KB_ARTICLE_EDIT’
Permission.create :name => ‘KB_ARTICLE_DELETE’

administrator role

admin_role = Role.create :name => ‘Administrator’, :description => ‘Top
level role with full permissions’
Permission.find(:all).each do |p|
admin_role.permissions << p
end

create root user

root_user = User.create(
:first_name => ‘Root’,
:surname => ‘User’,
:short_name => ‘Root’,
:username => ‘rootuser’,
:password => ‘rootpass’,
:email_address => ’ [email protected]
)
root_user.roles << admin_role
root_user.save

The line its falling over on is the root_user = User.create method. I
don’t
think its because of the way I’ve laid it out over several lines - I’ve
tried it with and without the parentheses and all on one line as well.
I’ve
also tried just setting one or two of the fields.

Here is my schema definition for the user table:

create_table “users”, :force => true do |t|
t.column “surname”, :string, :limit => 100
t.column “first_name”, :string, :limit => 100
t.column “short_name”, :string, :limit => 30
t.column “username”, :string, :limit => 30
t.column “password”, :string, :limit => 40
t.column “email_address”, :string
end
add_index “users”, [“id”], :name => “id”, :unique => true

And here is a backtrace:

/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:465:in
initialize' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:465:increate’
./db/migrate//002_initial_user_data.rb:29:in up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:211:inmigrate’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:206:in
each' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:206:inmigrate’
/usr/lib/ruby/gems/1.8/gems/activerecord-
1.13.0/lib/active_record/migration.rb:173:in
up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:164:inmigrate’
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/tasks/databases.rake:3
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/tasks/databases.rake:2:in
call' /usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:inexecute’
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in each' /usr/lib/ruby/gems/1.8/gems/rake- 0.6.2/lib/rake.rb:202:inexecute’
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:180:in invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:inrun’
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in each' /usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:inrun’
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/bin/rake:7
/usr/bin/rake:18

Help! I’m stumped.

Cheers
Luke

What does your User model look like? Have you defined an initialize
method for it? (That’s kind of what it looks like, from the backtrace
anyway). If so, please note that the initialize method is special for
ActiveRecord, and you should use the after_find/after_initialize
hooks to do on-creation initialization, rather than overriding the
initialize method.

  • Jamis

Ah! Thanks Jamis, yes, I did have an initialize method. I will change
this.

Cheers
Luke

Hi,

I was wondering if anyone has any experience with livetree, or knows
where to find people that do.

thanks
-Chris

sorry about the subject the first time…