1
0

More than 1 year has passed since last update.

カラムを追加しても反映されない時の対処法

Last updated at Posted at 2023-09-08

今回の躓いてた原因を残しておく
XXXXX_sorcery_core.rbの中身は以下の通り

class SorceryCore < ActiveRecord::Migration[7.0]
  def change
    create_table :users do |t|
      t.string :email,            null: false, index: { unique: true }
      t.string :crypted_password
      t.string :salt
    end
  end
end

この状態で1回目のrails db:migrateを行った
その後first_name,last_nameカラムがひつようになったため
XXXXX_sorcery_core.rbを以下のように書き変えた

class SorceryCore < ActiveRecord::Migration[7.0]
  def change
    create_table :users do |t|
      t.string :email,            null: false, index: { unique: true }
      t.string :crypted_password
      t.string :salt
      t.string :first_name,        null: false
      t.string :last_name,         null: false
    end
  end
end

ここで2回目のrails db:migrateを行うも反映されない
原因は一度マイグレーションを実行したファイルは
もう一度rails db:migrateを実行しても変更がされないらしい
そこで

$ rails db:migrate:reset

を実行してから再度

$ rails db:migrate

を実行するとカラムの追加ができた

初学者で知識がないというのは承知の上だが、だとしても初見殺しが多すぎないか?

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