http://api.rubyonrails.org/classes/ActiveRecord/Migration.html
change_column(table_name, column_name, type, options): Changes the
column to a different type using the same parameters as add_column.
Original Migration:
class CreateBooks < ActiveRecord::Migration
def self.up
create_table :books, :force => true do |t|
t.string :name, :default=>"NUlL"
t.timestamps
t.integer :lock_version, :null => false, :default => 0
end
end
def self.down
end
end
#script/console
>> Book.new
=> #<Book id: nil, name: "NUlL", created_at: nil, updated_at: nil,
lock_version: 0>
Modify The Book's Name Column:
class ModifyBookNameColumn < ActiveRecord::Migration
def self.up
change_column :books, :name, :string, :default => "Lake"
end
def self.down
end
end
#script/console (notice the name is not "NULL" but is "Lake")
>> Book.new
=> #<Book id: nil, name: "Lake", created_at: nil, updated_at: nil,
lock_version: 0>
>>
--
Posted via http://www.ruby-forum.com/.