KahelAMP!

Life, Linux and Web Development in KahelOS… OK, in general…

doctrine:build Errors

leave a comment »

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:

  1. Check the key type on the referenced table.
  2. Adjust your foreign key type accordingly.
  3. Rebuild your models.
Advertisement

Written by agi

January 11, 2010 at 9:51 pm

Posted in lamp

Tagged with , , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.