RoR‎ > ‎

Unsigned Int for migration

currently rails only allow signed int for migration, but for best practice it's better to use unsigned int for some cases you can force migration to unsigned int by doing something like this
t.column :unsigned_value, "integer unsigned"
but that kinda ugly to see. luckily rob anderton ( already created monkey patch to add unsigned support:
the patch will add :unsigned option in migration so you can do something like this:
t.integer :unsigned_value, :unsigned => true
furthermore the patch will make default table id and foreign key to unsigned int(11), but make sure to use t.references to create foreign key or simply use :unsigned => true

important things:

- for existing project this patch might break table relation because it will create unsigned int foreign key but the primary key might be signed int from old migration
- some plugin like role_requirement will generate migration that using t.integer for foreign key instead of t.references, you need to change this manually
- the patch will only change mysql adapter, so it will not work for other adapter