database - Adding index :unique to a column in ruby on rails via generate migration -
i know can touch migration , add
add_index :table_name, :column_name, :unique => true
but how right rails migration command generate this?
rails g migration add_index_to_column_name :column_name, :unique => true
is right?
in special example have table customers
t.integer :customerid t.string :surname t.string :first_name t.string :phone
an want set customerid unique. tried
rails g migration addindextocustomers :customerid, :unique => true
but if migration file after this, dont right see this:
def change add_column :customers, :, :customerid, add_column :customers, :, :unique add_column :customers, :=, :string end
any idea or suggestion?
starting rails 3.2 able use:
rails g migration add_index_to_table_name column_name:uniq
example http://guides.rubyonrails.org/3_2_release_notes.html
rails g scaffold post title:string:index author:uniq price:decimal{7,2}
upd i'm sorry. default type if don't pass string. can pass type yourself.
column_name:type:uniq
thus example should looks like:
rails g migration add_index_to_customers customerid:integer:uniq
Comments
Post a Comment