How to create a migration to remove an index only if it exists, rather than throwing an exception if it doesn't?

前端 未结 3 1795
攒了一身酷
攒了一身酷 2021-02-03 18:29

Right now, the current migration might fail, if the books table doesn\'t have created_at or updated_at fields:

class AddTi         


        
3条回答
  •  不知归路
    2021-02-03 18:53

    There is also index_name_exists?(table_name, index_name) method which let's you check for an index by it's name. It's helpful for checking for existence of multi-column indexes.

    Documentation - index_name_exists

提交回复
热议问题