LoginSignup
10
6

More than 3 years have passed since last update.

rails db:migrateエラーのStandardError: An error has occurred, all later migrations canceled:の解決法

Posted at

StandardError: An error has occurred, all later migrations canceled:エラーの解決法について

rails db:migrateしようとした際にでたエラーです。
エラーが発生したのでマイグレーションキャンセルしたよ!というエラーですね。

ActiveRecord::StatementInvalid: Mysql2::Error: Table 'アプリ名_development.カラム名' doesn't exist: SHOW FULL FIELDS FROM users

エラーをみていくとこのような文がありました。

原因

原因はマイグレーションファイルでした。

作成期日_create_posts.rb
class CreatePosts < ActiveRecord::Migration[5.2]
  def change
    create_table :posts do |t|
      t.string :content
      t.references :user, foreign_key: true
      t.timestamps
    end
  end
end

referencesはuser_idという形でDBに反映されるのですが作ろうとしているuser_idはbigint型。
対して外部キーで参照したいusersテーブルのidがinteger型なので、型が合わずエラーになるようです。

なので、integer型にします。

作成期日_create_posts.rb
class CreatePosts < ActiveRecord::Migration[5.2]
  def change
    create_table :posts do |t|
      t.string :content
      t.integer :user_id
      t.timestamps
    end
  end
end

これでマイグレーション通りました。

参考: https://qiita.com/umeneri/items/b46c537661f612f7318b

最後までご覧いただきありがとうございました。

10
6
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
10
6