LoginSignup
3
3

More than 3 years have passed since last update.

【DBエラー解決】Error: Duplicate column name ''"

Posted at

はじめに

$ rails db:migrate した際にDBには反映されているがエラーが起こっている解決策について調べたのでまとめました。

今回の状況

$ rails db:migrate
⬇︎
エラー発生
⬇︎
エラーなのにDBにはカラムが反映されている

エラー内容

andardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Duplicate column name '' ・・・・・
・
・
・
・

これはカラムが重複していますと言うエラーだそうです。

解決策

command + f でmigrationファイルの中身を空にする。

class AddCategoryToItems < ActiveRecord::Migration[5.2]
  def change

   ここを空にする

  end
end

空の状態で $ rails db:migrate すると通る。

command + f で切り取ったコードをペーストしてもとに戻しておく。

以降 $ rails db:migrate してもエラーになりません!

まとめ

Mysql2::Error: Duplicate column name ''

このエラーはカラムが重複していますよと言うエラー内容でした

migrationファイルを空にしてから $ rails db:migrate

その後migrationファイルの中身はもとに戻しておく。

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