💨

ActiveRecord::Fixture::FixtureError

2023/04/29に公開

Fixture error

RailsTutorial13章で発生したエラーの自分用メモを再編集しています。
誰かの参考になるかどうか気にしていません。

ActiveRecord::Fixture::FixtureError: table "microposts" has no columns named "micropost_0",”micropost_1”,・・・

tutorialを遡り関連していそうな変更を加えたファイルをひとつずつ確認。
×(Cloud9のコードエディター行頭に出るやつ)が出ている部分があったので修正

$ rails db:migration:reset
$ rails db:seed

→エラーのまま

インデント関連で同様のfixtureエラー出ている人がネットの海にいたので該当のfixture/micropostsを見本と比較

修正前

<% 30.times do |n| %>
  micropost_<%= n %>:
  content: <%= Faker::Lorem.sentence(word_count: 5) %>
  created_at: <%= 42.days.ago %>
  user: michael
<% end %>

修正後

<% 30.times do |n| %>
micropost_<%= n %>:
  content: <%= Faker::Lorem.sentence(word_count: 5) %>
  created_at: <%= 42.days.ago %>
  user: michael
<% end %>

コピペした際に自分でインデントしてしまっていた。
テストしたところ先のfixtureエラーは発生せず、別のエラーが発生。
Viewを正しく書けていなかった。13章よりも前の部分での変更点の見落としとみられる。
エラーコードを読み解決。

Discussion