unsigned int in migration

35 views
Skip to first unread message

eugenio

unread,
Nov 22, 2009, 11:44:36 AM11/22/09
to Ruby on Rails: Talk
i noticed that rails create signed int(11) for id fields (i'm using
mysql, i don't know if it acts like this with different databases).
i think that unsigned is better for primary keys (and foreign keys).
Is there an easy way to indicate that in a migration?

Jeffrey L. Taylor

unread,
Nov 23, 2009, 4:35:41 AM11/23/09
to Ruby on Rails: Talk
This comes up occassionally. The current answer is no. My quess is that not
all supported databases support unsigned. There is a way to create an
unsigned int column (that I've forgotten) but it isn't carried over to the
test database. So you can used unsigned ints, just cant' test the upper half
of the values.

Jeffrey

Matt Jones

unread,
Nov 23, 2009, 11:13:03 AM11/23/09
to Ruby on Rails: Talk
There's not a way to do so, as far as I know. Somewhat offtopic, why
do you believe that unsigned is preferable? Yes, it has twice as much
range, but if your DB has 2 billion objects in it and needs more -
you've likely got other problems...

eugenio

unread,
Nov 23, 2009, 11:26:03 AM11/23/09
to Ruby on Rails: Talk
you are right.
but because they're use the same memory i thought it would be correct
to let the application to use all of them if needed.
i think it's just a mysql habit i got.
thanks.

Greg Donald

unread,
Nov 23, 2009, 11:31:52 AM11/23/09
to rubyonra...@googlegroups.com
On Mon, Nov 23, 2009 at 10:13 AM, Matt Jones <al2...@gmail.com> wrote:
> There's not a way to do so, as far as I know. Somewhat offtopic, why
> do you believe that unsigned is preferable? Yes, it has twice as much
> range, but if your DB has 2 billion objects in it and needs more -
> you've likely got other problems...

When I know up front I will never store a negative value in there I
change it to unsigned using an execute statement. It has nothing to
do with capacity but has everything to do with data integrity.



--
Greg Donald
http://destiney.com/
Reply all
Reply to author
Forward
0 new messages