symfonypdodoctrinedoctrine-migrations

How to set field to null on doctrine migrations using addSql?


I'm updating an entity in one of my doctrine migrations with Doctrine\DBAL\Migrations\AbstractMigration::addSql($sql, array $params = array(), array $types = array()), I have to set up a column as null.

I have already debugged it and I tried to set up the type as \PDO::PARAM_NULL but I'm getting the same issue.

SQL:

    $sql="INSERT INTO sme_task_template (status_change_final_status) VALUES (:finalStatus)";
    $params=array(
        'finalStatus' => null
    );
    $types=array(
        'finalStatus' => \PDO::PARAM_NULL
    );
    $this->addSql($sql, $params, $types);

Exception:

  [Doctrine\DBAL\DBALException]                                                
  An exception occurred while executing 'INSERT INTO sme_task_template (statu  
  s_change_final_status) VALUES (:finalStatus)' with params [null]:            
  Value for :finalStatus not found in params array. Params array key should b  
  e "finalStatus"

Does anyone know how to solve this?

Thanks


Solution

  • I can't get it working with named parameters but it seems to work with question mark parameters.

        $sql="INSERT INTO sme_task_template_trigger (status_change_final_status) VALUES (?)";
        $params=array(
            null
        );
        $types=array(
            \PDO::PARAM_NULL
        );
        $this->addSql($sql, $params, $types);