Integer limit on migration doesn't have any effect?


#1

I have this code on migration file

t.column :some_integer, :integer, :limit => 4
t.column :other_integer, :integer, :limit => 8

on mysql, I checked the datatype:
some_integer INT(4)
other_integer INT(8)

but when I tried to enter a really big number to both fields (5
billion which is bigger than INT(4) )
both got truncated to 2147483647 which is the max for INT(4), and it’s
the same when I use :limit=>2 or :limit => 1

is this mysql issue? I’m using mysql 4.1


#2

Reynard wrote:

but when I tried to enter a really big number to both fields (5
billion which is bigger than INT(4) )
both got truncated to 2147483647 which is the max for INT(4), and it’s
the same when I use :limit=>2 or :limit => 1

is this mysql issue? I’m using mysql 4.1

If you insert some values directly in MySQL do you have the same
problem?


Michael W.


#3

Yes it seems like mysql considers INT(n) the same as INTEGER (at least
on version 4.1 on mybox)
try doing this from mysql console
create table test (num INT(2));

it will create num as INTEGER not tinyint or smallint

if you want to specifically use smallint, tinyint, or bigint you just
have to specify

t.column :big_integer, :bigint
t.column :small_integer, :smallint
t.column :tiny_integer, :tinyint

so the :limit option is useless on mysql, is this correct?

  • reynard