Check if a table exists in Rails

后端 未结 5 496
旧时难觅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条回答
  •  猫巷女王i
    2021-01-29 20:15

    Rails 5.1

    if ActiveRecord::Base.connection.data_source_exists? 'table_name'
       drop_table :table_name
    end
    

    or

    drop_table :table_name, if_exists: true
    

提交回复
热议问题