my story blog

JavaScriptとかRubyの技術的なことを書きたい

The single-table inheritance mechanism failed to locate the subclass

railsUser.all()などとsqlを発行したとき、このエラーが発生する

>> User.all()
  User Load (12.1ms)  SELECT "users".* FROM "users" 
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'XXX'. 
This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite User.inheritance_column to use another column for that information.

...以下略

メッセージにも書いてある通りtypeというカラムが予約後となっているためエラーになってしまうようです。 カラム名を変更などしましょう。

railsの予約後一覧

railsは3.2.11です

おまけ

カラム名を変更する方法

$ rails g migration change_user_col

作成されたmigrationファイル(例:db/migrate/20130424113832_change_user_col.rb)に以下を記述

def up
  rename_column(:users, :type, :user_type)
end

migrationする

$ rake db:migrate