我知道我可以touch 移民并添加
add_index :table_name, :column_name, :unique => true
但是,正确的rails迁移命令是如何生成的呢?
rails g migration add_index_to_column_name :column_name, :unique => true
是那么回事吗?
在我的特殊示例中,我有一个表客户
t.integer :customerID
t.string :surname
t.string :first_name
t.string :phone
A我要将customerID设置为唯一.已try
rails g migration AddIndexToCustomers :customerID, :unique => true
但是,如果我在此之后查看我的迁移文件,它看起来不太对劲,如下所示:
def change
add_column :customers, :, :customerID,
add_column :customers, :, :unique
add_column :customers, :=, :string
end
有什么 idea 或建议吗?