Indicates whether the table associated with this class exists
# File activerecord/lib/active_record/base.rb, line 745 def table_exists? if connection.respond_to?(:tables) connection.tables.include? table_name else # if the connection adapter hasn't implemented tables, there are two crude tests that can be # used - see if getting column info raises an error, or if the number of columns returned is zero begin reset_column_information columns.size > 0 rescue ActiveRecord::StatementInvalid false end end end
When using ActiveRecords in initializers, eg. for creating small constant data on startup, use table_exists? for those statements.