Search code examples
phpmysqlsymfonydoctrine-ormdoctrine

Prevent "Migration executed but did not result in any SQL statements" message when running custom SQL in Doctrine migration


I am executing manual prepared statements in my Doctrine migration. I am doing this as I require the last inserted ID to build further related queries. Using the standard addSql method does not allow for this due to the nature of it "lining up" the queries and then executing them at the end.

Is there a way I can prevent the following error message from displaying?

Migration 20151102112832 was executed but did not result in any SQL statements.

There are many SQL statements executed, however they are execute when calling this method of mine:

/**
 * @param string $sql
 *
 * @throws DBALException
 */
private function runSql($sql)
{
    $this->write($sql);
    $stmt = $this->connection->prepare($sql);
    $stmt->execute();
}

Solution

  • You can create a "do nothing" sql:

    public function up(Schema $schema)
    {
        $this->addSql('SELECT 1');
    }