Rails カラム名でエラーとカラム名称変更

個人開発したアプリの宣伝
目的地が設定できる手帳のような使い心地のTODOアプリを公開しています。
Todo with Location

Todo with Location

  • Yoshiko Ichikawa
  • Productivity
  • Free

スポンサードリンク

エラー

Railsのカラム名にtypeという名称を使用していると以下のようなエラーが出る

/app/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.2.1/lib/active_record/inheritance.rb:226:in `rescue in find_sti_class': The single-table inheritance mechanism failed to locate the subclass: 'matome'. 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 GameCategory.inheritance_column to use another column for that information. (ActiveRecord::SubclassNotFound)

参考: qiita.com

カラム名の変更

リネームしたほうが良さそうなので、大人しくリネームする

class ModColumnNameToTableName < ActiveRecord::Migration[5.2]
  def change
    rename_column :table_name, :type, :new_column_name
  end
end