# Step 1: Create a new Rails migration to add a new column to an existing table
rails generate migration AddColumnNameToTableName column_name:data_type
# Step 2: Open the generated migration file and define the changes
# In the migration file (db/migrate/YYYYMMDDHHMMSS_add_column_name_to_table_name.rb)
class AddColumnNameToTableName < ActiveRecord::Migration[6.0]
def change
add_column :table_name, :column_name, :data_type
end
end
# Step 3: Run the migration to apply the changes to the database
rails db:migrate
# Optional Step: If you need to rollback the migration
rails db:rollback
# Optional Step: If you want to generate a model for the updated table
rails generate model ModelName
# Optional Step: Run the new migration for the model
rails db:migrate