devroom.io/drafts/2009-08-20-once-and-for-all-rails-migrations-integer-limit-option.md
Ariejan de Vroom dbae98c4c0 Moar updates
2013-03-24 14:27:51 +01:00

1.1 KiB

title kind slug created_at tags
Once and for all: Rails migrations integer :limit option article once-and-for-all-rails-migrations-integer-limit-option 2009-08-20
MySQL
Ruby on Rails
Rails
sql
migrations
integer
limit

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):

:limit Numeric Type Column Size Max value
1 tinyint 1 byte 127
2 smallint 2 bytes 32767
3 mediumint 3 byte 8388607
nil, 4, 11 int(11) 4 byte 2147483647
5..8 bigint 8 byte 9223372036854775807

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.