Migrations now have a timestamp as their version number in Rails 2.1. In this episode I will explain this change as well as show you some other cool additions.
# in a migration file
def self.up
change_table :products do |t|
t.rename :released_on, :released_at
t.change :description, :text, :limit => nil, :null => true
t.remove :price
t.integer :stock_quantity
end
end
def self.down
change_table :products do |t|
t.rename :released_at, :released_on
t.change :description, :string, :null => false
t.decimal :price, :precision => 10, :scale => 2
t.remove :stock_quantity
end
end
在Rails2.1中,迁移文件使用时间戳作为版本号。本篇介绍此变更,并展示了如何通过更改表来更新字段类型及名称。
143

被折叠的 条评论
为什么被折叠?



