Zac Mullett Engineering Services
Weblog

Archive for October, 2010

Unicode file format for YAML fixtures file

Saturday, October 2nd, 2010

Running a doctrine:data-load on my Symfony web project’s data/fixtures.yml file and finding an empty database was my latest infuriation. I narrowed it down to some of the data having a Unicode character (the offending letter: รถ).

Initially I thought it may be the format that the database was configured to communicate or store in. While the collation was the default latin1_swedish_ci, this isn’t the problem because the collation only defines the rule set by which text is compared. I also found no settings restricting the input or storage form.

The problem was the storage format of the data/fixtures.yml file. Despite my text editor (TextPad in this case) being able to interpret the characters correctly in their 8-bit extended ANSI form, the Doctrine processor does not. You simply must save the file as Unicode format and it will then interpret correctly.

Oops moment with YAML “onDelete: SET NULL”

Friday, October 1st, 2010

I’ve begun using the Symfony MVC framework for a website I am developing. When trying to perform a doctrine:build to rebuild the database, I was noticing an error:

SQLSTATE[HY000]: General error: 1005 Can’t create table ‘mta.#sql-b90_1e0′ (errno: 150). Failing Query: “ALTER TABLE mta_album_instance ADD CONSTRAINT mta_album_instance_author_user_id_mta_user_id FOREIGN KEY (author_user_id) REFERENCES mta_user(id) ON DELETE SET NULL”. Failing Query: ALTER TABLE mta_album_instance ADD CONSTRAINT mta_album_instance_author_user_id_mta_user_id FOREIGN KEY (author_user_id) REFERENCES mta_user(id) ON DELETE SET NULL

Initially I was thrown because it writes “Can’t create table” for table that has clearly been created. Also it repeats itself just to make it a little harder to read. This is about adding a foreign key constraint though.

I want to set up my table so that a deletion in the foreign table will set a column to null. In Doctrine YAML this looks like so:

relations:
  MtaUser: { local: author_user_id, foreign: id, onDelete: SET NULL }

From the error output, the reason for the problem wasn’t obvious. It turned out to be that the column had a ‘not null’ attribution. Once this was removed everything was good.

author_user_id: { type: integer, notnull: true }

I hope this helps somebody.