[Ruby] I changed the column name, but I was told the Undefined method for the column before the change

less than 1 minute read


・Ruby 2.5.7 ・Rails

Attempting to save a new record by changing the column name causes an error

It is called Undefined method script_id. Screenshots 2020-08-13 17 11 14

However, when I look at schema.rb (before change: script_id → after change: joke_book_id), it has changed…


t.integer "joke_book_id"
t.integer "user_id"
t.text "introduction"

So where is this script_id?

Conclusion: I didn’t change the model

After various investigations, I find that the model is suspicious. Looking at the model, Validated: :script_id, {presence: true}. Change here to a new column. validates :joke_book_id, {presence: true}


# validates :script_id, {presence: true} #Before change

validates :joke_book_id, {presence: true} # after change

It worked! ! !