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'
The class
Doctrine\DBAL\Migrations\Configuration\Configuration
itself is instantiated in theDoctrine\DBAL\Migrations\Tools\Console\Helper\ConfigurationHelper
, that is created inDoctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand::getMigrationConfiguration
. There seems to be a way to use a custom helper, that can create custom classes for Configuration and then Version, but that's a far fetched solution.If you only need it temporary to fix the schemas to make Migrations in sync with the DB state again, this may not be a the solution of your choice. Ignoring Exceptions shouldn't be permanently implemented.