Save doesn't work in migration

I’m writing a migration to merge my first and last name fields into a
single name field. However, writing to the new name column doesn’t
work within the migration. Why is this so?

def self.up
add_column :users, :name, :string

for user in User.all
user.name = user.first_name + ’ ’ + user.last_name
user.save! # <= name is not actually saved here.
end

remove_column :users, :first_name
remove_column :users, :last_name
end

Never mind, after some Googling, found reset_column_info to be my
answer.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs