migrations
migrations copied to clipboard
Migration fails when calling `OPTIMIZE TABLE` in `addSql`
Bug Report
| Q | A |
|---|---|
| BC Break | don't know |
| Version | 3.0.3 |
| MySQL | 5.7 |
Summary
I am converting character sets of multiple tables in a migration and as the final step in the process I need to do OPTIMIZE TABLE for all converted tables, but when I have more than one such statement, I get:
[Doctrine\DBAL\Exception\DriverException]
An exception occurred while executing 'OPTIMIZE TABLE `table1`;':
SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
How to reproduce
$this->addSql('OPTIMIZE TABLE `table1`;');
$this->addSql('OPTIMIZE TABLE `table2`;');
Could possibly be related to https://github.com/doctrine/migrations/issues/1004, but I don't understand if there's any way to work around this problem.