Once and for all: Rails migrations integer :limit option

I literally always have to look up the meaning of :limit in migrations when it comes to integer values. Here’s an overview. Now let’s memorise it (oh, this works for MySQL, other databases may work differently):

:limitNumeric TypeColumn SizeMax value
1tinyint1 byte127
2smallint2 bytes32767
3mediumint3 byte8388607
nil, 4, 11int(11)4 byte2147483647
5..8bitint8 byte9223372036854775807

Note: by default MySQL uses signed integers and Rails has no way (that I know of) to change this behaviour. Subsequently, the max. values noted are for signed integers.

  • Twitter
  • Digg
  • del.icio.us
  • DZone
  • Reddit
  • email

3 Responses to “Once and for all: Rails migrations integer :limit option”

  1. FYI: Choosing your column sizes correctly can improve MySQL performance dramatically.

  2. Ciaran Lee says:

    Oh cool, this really helped me – thanks!

  3. THANKS! This is really useful – where can I find this in the Rails API docs?

Leave a Reply