Monday, March 30, 2009

superclass mismatch for class Item

I had an "superclass mismatch for class Item" when I ran rake db:migrate. It was because I defined the same class twice. The model class is Item and I happened to have another class Item in my migration.
mir% grep -R 'class Item' .
./test/unit/item_test.rb:class ItemTest < Test::Unit::TestCase
./app/models/item.rb:class Item < ActiveRecord::Base
./db/migrate/20090325060057_item.rb:class Item < ActiveRecord::Migration
I changed the class name in 20090325060057_item.rb from Item to AlterItem, but this was not enough. This gives me rather hard to corelate error message:
undefined method `migrate' for Item(id: integer, created_at: datetime, updated_at: datetime):Class
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1833:in `method_missing_without_paginate'
/usr/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:170:in `method_missing'
It turned out that it was caused by filename and class name mismatch. I had to change the filename to 20090325060057_alter_item.rb to match with AlterItem class name.

No comments: