symfonyで出力されたSQL文でMySQLのテーブル生成時に「Some problems occurred when executing the task:~」

Practical symfony 3日目を参考に作業中、schema.ymlから作成したSQL文からMySQLにテーブルを作成する際、つまずいたところがあったので対処方法を調べました。

環境
  • MySQL 5.5.11
  • symfony 1.4.11

 

エラー部分
#php symfony propel:insert-sql
(略)
[propel-sql-exec] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Type=InnoDB' at line 7
(略)
 Some problems occurred when executing the task: If the exception message is not clear enough,  read the output of the task for more information

原因は、テーブルの種類の指定の際、MySQL5.5では「Type=InnoDB」という記述ではなく、「Engine=InnoDB」としなければならないためでした。

Note

The older TYPE option was synonymous with ENGINE. TYPE was deprecated in MySQL 4.0 and removed in MySQL 5.5. When upgrading to MySQL 5.5 or later, you must convert existing applications that rely on TYPE to use ENGINE instead. 引用元:http://dev.mysql.com/doc/refman/5.5/en/create-table.html

SQL文が記述されたファイル内の「Type=」を手動で「Engine=」とすればとりあえずは問題ないのですが、大元のSQL文生成スクリプトを修正することにしました。

#vi /path/to/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/builder/sql/mysql/MysqlDDLBuilder.php

でファイルを開いて、156行目の

$script .= "Type=$mysqlTableType";

$script .= "Engine=$mysqlTableType";

とします。

これで生成されるSQL文では最初から「Engine=」と記述されます。