CakePHP Migrations: INTEGER gotchas
Okay.. today i played around with the wonderful migrations implementation from Joel Moss and found some stuff in regard of typing in YAML.
First of all: It’s a pain in the ass – Secondly: It’s a breeze when it’s done.
Some beginners, just like me, may have wondered about why your generated schema does not reflect the exact layout after doing “migrate up” with the exact same file. For now i will get at the integers, because i think they are quiet important to know and i at least couldn’t find anything about it.
You can basicly set any integer type using YAML, but you need to know what length will be translated to what. Here is a small chart explaining just that.
- length: 1 => tinyint(4)
- length: 2 => smallint(6)
- length: 3 => mediumint(9)
- length: 4 => integer(11)
Everything greater than 4 will become bigint(20). If we look at length as a setting for the sub-fieldtype rather than being the real length of the field, this all makes sense. Dont bother trying to set length to 11 .. it wont help.


This will be an MDB2 thing. But – you will be glad to know – I am currently working on improving the schema management methods in the Cake core, which will be used by Migrations. So no more reliance on Pear and MDB2. Expect to see these in Cake 1.3.
Thanks for the tip, even I didn’t know this one.
cheers