environment ruby-2.6.3
During the development process, I had to change the column names. I will write down the coping method as a memorandum.
Change the column name of model user as follows
zipCode → zip_code
Execute the following command db/migrate/20200825114039_rename_zip_code_column_to_users.rb Create a.
rails generate migration rename_zipcode_to_users
db/migrate/20200825114039_rename_zip_code_column_to_users.rb
class RenameZipCodeColumnToUsers < ActiveRecord::Migration[6.0]
def change
rename_column :users, :zipCode, :zip_code
end
end
Do the following
$ rake db:migrate
The column name of the users model has been changed from zipCode to zip_code! </ b>
Initially, after rewriting the column name in the code I thought I should do "rake db: migrate", but it wasn't.
It's a little troublesome until you get used to it, but even if you make similar mistakes in the future It seems that we can deal with it calmly.
Recommended Posts