Skip to main content

Once and for all: Rails migrations integer :limit option

·99 words·1 min· ·
MySQL Ruby on Rails Rails Sql Migrations Integer Limit
Ariejan de Vroom
Author
Ariejan de Vroom
Jack of all Trades, Professional Software Craftsman

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.

Related

BaseApp: a quick start for your Rails App
·303 words·2 mins
General Ruby Ruby on Rails Rails BaseApp
Debian Etch: RMagick LoadError
·148 words·1 min
General RubyOnRails Ruby Ruby on Rails Rails Imagemagick LibMagickWand Magick Rmagick
Ruby on Rails plugin: Throttler
·40 words·1 min
Blog Ruby Ruby on Rails Rails Plugins Throttling Throttler