How to create a column of type tinyint(2) or tinyint(3) in Ruby on Rails?

maxedison picture maxedison · Jan 30, 2014 · Viewed 15.7k times · Source

In Ruby on Rails, the following code in a migration creates a column of type tinyint(4) in MySQL:

create_table :great_table do |t|
    t.integer :step_position, :limit => 1 #tinyint
end

How would I create a column of type tinyint(2) or tinyint(3)?

Answer

srbhattarai picture srbhattarai · Sep 15, 2014

For tinyint(2)

create_table :great_table do |t|
  t.integer :step_position, :limit => 2
end

For tinyint(3)

create_table :great_table do |t|
  t.integer :step_position, :limit => 3
end