unsigned int in migration

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?

Quoting eugenio <eugenio.modesti@gmail.com>:

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?

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

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...

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.

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.