Adding index :unique to a column in ruby on rails via generate migration

后端 未结 1 1150
南方客
南方客 2021-02-04 02:55

I know that i can touch a migration and add

add_index :table_name, :column_name, :unique => true

But how is the right rails migration comman

相关标签:
1条回答
  • 2021-02-04 03:20

    Starting from Rails 3.2 you able to use:

     rails g migration add_index_to_table_name column_name:uniq
    

    example from 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. The default type if you don't pass it would be string. You can pass type by yourself.

    column_name:type:uniq
    

    Thus your example should looks like:

    rails g migration add_index_to_customers customerID:integer:uniq
    
    0 讨论(0)
提交回复
热议问题