the best migration script is right here: models_with_files = ActiveRecord::Base.descendants.reject(&:abstract_class?).inject({}) do |reducer, model| columns = model.column_names.map { |c| $1 if c =~ /(.+)_file_name$/ }.compact if columns.size > 0 reducer[model.to_s] = columns.first end reducer end models_with_files.map do |model_name, file_name| model = Object.const_get(model_name) model.column_names.each do |column| next unless column.include?("#{file_name}_") puts "remove_column :#{model.table_name}, :#{column}" end end