Open
Description
Bug Report
Q | A |
---|---|
BC Break | no |
Version | 1.8.1 |
Summary
generates incorrect up migration but down is ok
Current behavior
generated migration just throw exception becous it should first remove constrant and then remove index
<?php declare(strict_types=1);
namespace DatabaseMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20181205094238 extends AbstractMigration
{
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP INDEX idx_7ee5e3886dc044c5 ON fields');
$this->addSql('CREATE INDEX IDX_7EE5E388D3CB4A96 ON fields (`group`)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE fields DROP FOREIGN KEY FK_7EE5E388D3CB4A96');
$this->addSql('DROP INDEX idx_7ee5e388d3cb4a96 ON fields');
$this->addSql('CREATE INDEX IDX_7EE5E3886DC044C5 ON fields (`group`)');
$this->addSql('ALTER TABLE fields ADD CONSTRAINT FK_7EE5E388D3CB4A96 FOREIGN KEY (`group`) REFERENCES field_groups (`id`)');
}
}
How to reproduce
* @ORM\ManyToOne(targetEntity="FarmField\Entity\FieldGroup")
* @ORM\JoinColumn(name="group", referencedColumnName="id")
changed to:
* @ORM\ManyToOne(targetEntity="FarmField\Entity\FieldGroup")
* @ORM\JoinColumn(name="`group`", referencedColumnName="id")
Expected behavior
generated valid migration maybe like this:
public function up(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE fields DROP FOREIGN KEY FK_7EE5E388FE54D947');
$this->addSql('DROP INDEX idx_7ee5e3886dc044c5 ON fields');
$this->addSql('CREATE INDEX IDX_7EE5E388D3CB4A96 ON fields (`group`)');
$this->addSql('ALTER TABLE fields ADD CONSTRAINT FK_7EE5E388FE54D947 FOREIGN KEY (`group`) REFERENCES field_groups (`id`)');
}