Last updated

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..8bigint8 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.