rails rename column and change type code example

Example 1: how to I change the name of a column in rails

$ rails g migration rename_season_to_season_id

class RenameSeasonToSeasonId < ActiveRecord::Migration
  def change
    rename_column :shoes, :season, :season_id
  end
end

Example 2: change column rails example

def change
    change_column(:table_name, :column_name, :new_type)
end

Example 3: rename column in db rails

class RenameTitleToNameInTasks < ActiveRecord::Migration[6.0]
  def up
    rename_column :tasks, :title, :name
  end

  def down
    rename_column :tasks, :name, :title
  end
end

Tags:

Ruby Example