0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Rails]migrateした際に発生した:An error has occurred, all later migrations canceled:エラーへの対処法

Last updated at Posted at 2020-12-09

【前提】
Rails 6.0.3.1
ruby 2.6.3

現在、オリジナルアプリを製作中。
その際に発生してしまったAn error has occurred, all later migrations canceledに対するエラーの解決方法についてみた。

20201020102544_create_bookmarks.rb. 

add_index :bookmarks, [:following_id, :follower_id, :follow_id, :followed_id], unique: true

・20201020102544_create_bookmarks.rbファイル内に上記内容のカラムをunique制約をかける為に記述

ターミナル.  
% rails db:migrate

Image from Gyazo

・ターミナルにてrails db:migrate_をかけた所、上記のようにrails aborted!
StandardError: An error has occurred, all later migrations canceled:エラーが発生した。よく見てみるとIndex name 'index_bookmarks_on_following_id_and_follower_id_and_follow_id_and_followed_id' on table 'bookmarks' is too long; the limit is 64 charactersと記述されており文字制限を超えていますと指摘されている事が発覚。

#before
add_index :bookmarks, [:following_id, :follower_id, :follow_id, :followed_id], unique: true

#after
add_index :bookmarks, [:following_id, :follower_id, :follow_id, :followed_id], unique: true, name: 'bookmarks_index'

・上記のようにname: 'bookmarks_index'を追加して記述して再度rails db:migrateを実行すると復旧しました

※まとめ※
まさか、migrationファイルにも文字制限があるとは思いませんでした:joy:かなり基本的な事だけど、また一つ勉強になりました。誰かの参考になると嬉しいです:relieved:

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?