How to Create a New Table With a Unique Index in an Active Record / Rails 4 Migration

前端 未结 5 1946
生来不讨喜
生来不讨喜 2021-02-01 12:41

How do I create a new table, through a rails migration, and add an unique index to it?

In the docs I found how to add a index to a table after it\'s been created, but h

5条回答
  •  青春惊慌失措
    2021-02-01 13:16

    You can create the table and index with the generator without changing the migration file

    For a unique index

    rails generate model CreateFoos bar:string:uniq
    

    For a non-unique index

    rails generate model CreateFoos bar:string:index
    

提交回复
热议问题