Check if a table exists in Rails

后端 未结 5 497
旧时难觅i
旧时难觅i 2021-01-29 19:35

I have a rake task that won\'t work unless a table exists. I\'m working with more than 20 engineers on a website so I want to make sure they have migrated the table before they

5条回答
  •  春和景丽
    2021-01-29 19:52

    The proper way to do this is Model.table_exists?

    class Dog < ApplicationRecord
      # something
    end
    
    do_something if Dog.table_exists?
    

提交回复
热议问题