[RUBY] I changed the column name, but it said Undefined method for the column before the change.

version

・ Ruby 2.5.7 ・ Rails 5.2.4.3

Trying to save a new record with a different column name but an error

It is called Undefined method script_id. スクリーンショット 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.

schema.rb


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

So where does this script_id come from?

Conclusion: I didn't change the model

After researching various things, I notice that the model is suspicious. Looking at the model, It was the same as before the change with validates: script_id, {presence: true}. Change here to a new column. validates :joke_book_id, {presence: true}

users_joke.rb


#validates :script_id, {presence: true} #Change before

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

It worked! !! !!

Recommended Posts

I changed the column name, but it said Undefined method for the column before the change.
[Must-see for beginners] I changed the display of the posting time to Japanese time [l method]
[Ruby on Rails] How to change the column name
[Rails] How to change the column name of the table
I translated [Clone method for Java arrays] as the Clone method in Java arrays.
How to dynamically change the column name acquired by MyBatis
[Rails] I tried using the button_to method for the first time
[Android] Change the app name and app icon for each Flavor