前提・実現したいこと
Ruby on Rails 初学者です。勉強しながらwebアプリ制作に挑戦しています。
データベースに初期値としてCSVファイルからレコードを取り込もうとしているのですが、エラーが出てうまくいきません。
エラーメッセージを読んでも分からず途方にくれています。
ぜひお力を貸していただきたいです。
発生している問題・エラーメッセージ
DEBUG -- : (2.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC rake aborted! ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'Type'. 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 Post.inheritance_column to use another column for that information. Caused by:NameError: uninitialized constant Type
該当のソースコード
ruby
1require "csv" 2 3CSV.foreach('db/restaurant.csv') do |info| 4 Post.create(:name => info[0], :comment => info[1], :type => info[2]) 5end 6
csvファイルの中身 マクドナルド,定番,ファストフード スターバックス,おしゃれ,カフェ 松屋,味噌汁つく,牛丼
補足情報(FW/ツールのバージョンなど)
Ruby 2.5.1p57
rails 5.2.0
PostgreSQL
PG version 10.4
テーブル名 posts
Column |Type
id |bigint
name |text
created_at |timestamp without time zone
updated_at |timestamp without time zone
comment |character varying(255)
type |character varying(255)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。