例如我有这个模型:
class Product < ActiveRecord::Base
attr_accessible :name, :order
end
然后当我这样做时,rake db:migrate
它创建了这个db/migrate/20120825132038_create_products.rb:
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.integer :order
t.string :name
t.timestamps
end
end
end
但这一切都发生了,因为我用过rails generate Product order:integer name:string
现在,在我转到产品模型并手动将其更改为:
class Product < ActiveRecord::Base
attr_accessible :name, :order, :category_id
validates :name, uniqueness: true
belongs_to :category
end
如何使用更新自动更新db/migrate/20120825132038_create_products.rb?