2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Nice tips about rails

Last updated at Posted at 2014-08-23

Add a column in a migration and populate it immediately after.
reset_column_information

Example

	class AddNameToUser < ActiveRecord::Migration
  		def self.up
    		add_column :users, :name, :string
    		User.reset_column_information
    		User.find(:all).each do |user|
      			user.name = user.first_name + ' ' + user.last_name
    		end
    		remove_column :users, :first_name
    		remove_column :users, :last_name
		end
  	end

2
2
1

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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?