0
0

More than 3 years have passed since last update.

rails db:migrationが通らなかった時に確認すべきこと

Posted at

いつものようにマイグレーションファイルを作成し、rails db:migrateをしようとしたところ以下のエラーがでた。
Column user_id on table entries does not match column id on users, which has type bigint(20). To resolve this issue, change the type of the user_id column on entries to be :bigint. (For example t.bigint :user_id).

指示通り以下のようにbigintを指定して再度マイグレーションを実施した。
class CreateEntries < ActiveRecord::Migration[5.1]
def change
create_table :entries do |t|
t.references :user, foreign_key: true, type: :bigint //integerからbigintに変更
t.references :room, foreign_key: true
t.timestamps
end
end
end

しかし、同様のエラーが出現した。
実はこの時3個のマイグレーションファイルを同時に作成しており、上記のマイグレーションファイルを登録するために必要なマイグレーションファイル(room)の作成日時が最後になっていたのでエラーが発生していた。
roomファイルの作成日時をファイル名を変更し、再度rails db:migrateを実行したところ問題なく通った。

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