LoginSignup
3
0

More than 3 years have passed since last update.

Rails 6.1.3にアップグレードした後に「undefined method `service_name' 」のエラーが発生する

Last updated at Posted at 2021-03-27

背景

https://github.com/rails/rails/issues/41750
上記のissueがあるので、プロジェクトのRailsバージョンを6.0.3から6.1.3にアップグレードする必要があります。

bundle update rails

bundleは無事に完成しました。
ただし、サーバーを再起動した後はimage_tagの部分は「undefined method `service_name' 」のエラーが発生しました。

原因

ActiveStorage::Blob#service_name column was added. It is required that a migration is run after the upgrade. Run bin/rails app:update to generate that migration.

Railsの6.1.3のバージョンで新たなservice_nameがactivestorageに追加されました。

解決方法

記載の通りにbin/rails app:updateを実行してもらうと既存の配置も変更されました。
配置変更なんてリスクが高いので、やらない方がいいと思います。
その故に、カラムを増やしたら、カラムを追加します。
activestorageをインストールする際と同じく、activestorageのテーブルを更新します。

rails active_storage:update
rails db:migrate

Railsサーバーを再起動して、問題が治されました。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0