Ruby on Rails and MySQL BIGINT

When creating a migration using Ruby on Rails and MySQL, the default MySQL type created when defining an integer field is an 11-digit signed int. This will allow you to store signed integers up to 2147483647.

However MySQL has the BIGINT storage type which stores signed integers up to 9223372036854775807.

In order to take advantage of the BIGINT storage with Rails migrations you first need to create a normal integer and then change the column to a BIGINT like so:

def self.up
  create_table(:people) do |t| 
    t.integer :number_of_facebook_friends
  end

  change_column :people, :number_of_facebook_friends, :bigint    
end