namespace Application\Migration;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160704163301 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$sql = <<<sql
ALTER TABLE `FOO`
ADD COLUMN `bar` TINYINT NOT NULL DEFAULT 1 AFTER `baz`;
sql;
try {
$this->addSql($sql);
} catch (\Doctrine\DBAL\Exception\NonUniqueFieldNameException $e) {
} catch (\Doctrine\DBAL\Driver\PDOException $e) {
} catch (\PDOException $e) {
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
}
}
How to make it silently executed if column already exists ? catch above still got error:
[Doctrine\DBAL\Exception\NonUniqueFieldNameException]
An exception occurred while executing ' ALTER TABLE `FOO`
ADD COLUMN `bar` TINYINT NOT NULL DEFAULT 1 AFTER `baz`;
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'bar'
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'bar'
[PDOException]
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'bar'
@SenseException Thank you for the suggestion ;)