Created
July 7, 2011 14:09
-
-
Save stream7/1069589 to your computer and use it in GitHub Desktop.
Rails migrations integer :limit option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
taken from http://ariejan.net/2009/08/20/once-and-for-all-rails-migrations-integer-limit-option/ |
Thanks for this gist. Really saved my bacon tonight!
Thanks for this important information 💯 👍
What's the default column size when :limit option is not specified?
What's the default column size when :limit option is not specified?
nvm. It's int(11) i.e. 4 bytes
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, Postgres doesn't support tinyint but Rails migrations handles that automatically and sets it to smallint.