Rails Migrations: List of Table Column Types

This list was compiled from rails 4, but may also be valid in earlier versions of rails. Use Active Record migrations to alter your database in a structured and organized manner.

List of attributes for SQL types:

list_column_types.rb
1
2
3
4
5
6
7
8
9
10
11
  :binary
  :boolean
  :date
  :datetime
  :decimal
  :float
  :integer
  :primary_key
  :string
  :text
  :time

You may also use database specific types, however this is not database agnostic and is to be used with caution.

migration_create_races.rb
1
2
3
4
5
6
7
8
9
10
11
class CreateRaces < ActiveRecord::Migration
  def change
    create_table :races do |t|
      t.datetime :date
      t.integer :track_id
      t.string :name

      t.timestamps
    end
  end
end
migration_add_round_to_races.rb
1
2
3
4
5
class AddRoundToRaces < ActiveRecord::Migration
  def change
    add_column :races, :round, :integer
  end
end

These are documented under column in the Active Record API.

Comments