【发布时间】:2012-08-20 18:24:12
【问题描述】:
例如我有这个模型:
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?
【问题讨论】:
标签: ruby-on-rails activerecord model rake