doctrine:build Errors
SQLSTATE[HY000]: General error: 1005 Can't create table 'db.#sql-57ef_a3' (errno: 150). Failing Query: "ALTER TABLE item ADD CONSTRAINT item_uom_id_uom_id FOREIGN KEY (uom_id) REFERENCES uom(id)". Failing Query: ALTER TABLE item ADD CONSTRAINT item_uom_id_uom_id FOREIGN KEY (uom_id) REFERENCES uom(id)
I encountered these types of errors when I was on the model conceptualization stage of a symfony project. The quickest fix I found was to set the problematic tables to MyISAM, then gradually opted to set the option globally at the expense of row-level locking.
You can do this either in the schema.yml or ProjectConfiguration.php. The error can still persist when setting this configuration in schema.yml and referencing a plugin table (such as sfGuardUser).
schema.yml
options:
type: MyISAM
ProjectConfiguration.php
class ProjectConfiguration extends sfProjectConfiguration
{
...
public function configureDoctrineConnection(Doctrine_Connection $connection)
{
$connection->setAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE, 'MyISAM');
}
}
MyISAM is generally considered faster and more stable than InnoDB, however latest benchmarks show that InnoDB is gaining ground against MyISAM. Most web applications and frameworks are also going on the direction of InnoDB. I investigated on this issue further while writing this article.
detect_relations: true
myExample:
columns:
id: integer
sf_guard_user_id: integer
The example above will result in an error on an old (pre r25546) revisions of sfDoctrineGuardPlugin as sfGuardUser:id is defined as an integer(4) field. Changing sf_guard_user_id to integer(4) will clear the error. So when having issues such as these but definitely want to stay with InnoDB:
- Check the key type on the referenced table.
- Adjust your foreign key type accordingly.
- Rebuild your models.

