Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent "Migration executed but did not result in any SQL statements" message when rnning 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();
}
like image 411
crmpicco Avatar asked Nov 03 '15 17:11

crmpicco


2 Answers

You can create a "do nothing" sql:

public function up(Schema $schema)
{
    $this->addSql('SELECT 1');
}
like image 167
Marek Avatar answered Sep 18 '22 12:09

Marek


I think the best option here to show what your migration is doing. You can do this and suppress warning message by sending sql request with comment string. For example:

public function up(Schema $schema)
{
    // Do not show warning on migrations.
    $this->addSql('# Updating entities.');
}
like image 40
Andriyun Avatar answered Sep 19 '22 12:09

Andriyun