Reputation: 5881
currently rails version 5.
In it I want to write the migration in condition that migration should run only when the field does not exist in the database for a particular table.
Please suggest how to implement it in rails, Thanks in advance.
Upvotes: 1
Views: 162
Reputation: 5881
def self.up
unless ActiveRecord::Base.connection.column_exists?(:table_name, :column_name)
add_column :table_name, :column_name, :data_type
end
end
Upvotes: 1