我正在我的Doctrine迁移中执行手动准备的语句。我正在这样做,因为我需要最后插入的ID来构建进一步的相关查询。使用标准addSql
方法不允许这样做,因为它的性质"排队"查询然后在最后执行它们。
有没有办法阻止显示以下错误消息?
Migration 20151102112832 was executed but did not result in any SQL statements.
执行了很多SQL语句,但是在调用我的这个方法时它们是执行的:
/**
* @param string $sql
*
* @throws DBALException
*/
private function runSql($sql)
{
$this->write($sql);
$stmt = $this->connection->prepare($sql);
$stmt->execute();
}
答案 0 :(得分:5)
你可以创建一个"什么都不做" SQL:
public function up(Schema $schema)
{
$this->addSql('SELECT 1');
}
答案 1 :(得分:1)
name price quantity total
ramesh 150 1 150
kumar 200 2 400
suresh 126 1 126
答案 2 :(得分:1)
我认为这里是显示您的迁移工作的最佳选择。 您可以执行此操作,并通过发送带注释字符串的sql请求来抑制警告消息。例如:
public function up(Schema $schema)
{
// Do not show warning on migrations.
$this->addSql('# Updating entities.');
}
答案 3 :(得分:0)
我使用时,Doctrine迁移版本3在MySQL5.7上引发了一个错误:
public function up(Schema $schema)
{
$this->addSql('SELECT 1');
}
错误消息:
[error] Migration DoctrineMigrations\Version20190823142208 failed during Post-Checks. Error: "An exception occurred while executing 'SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'':
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."
使用注释可以解决此错误:
public function up(Schema $schema)
{
$this->addSql('#prevent warning' ); //Prevent “Migration executed but did not result in any SQL statements”
}