Postgres sequences in CakePHP

Recently I added my company’s legacy database system to our new CRM system we are building with CakePHP. It worked wonderfully, until I tried to inject something into the legacy DB. As it turns out our old DB was built using sequences for the primary keys of all the tables. When this was combined with the fact that it used one of several schema in the same db, CakePHP simply could not find the sequence and the SQL failed.

As it turns out it is easy to configure the model to use a sequence. I ended up with the following as an example:

Take note that you need to include the schema and double quotes in the sequence string for it to work (At least with a schema that is not ‘public’).