diff --git a/migrations/Version20230108165410.php b/migrations/Version20230108165410.php index 4118d5ad..9e0d8cca 100644 --- a/migrations/Version20230108165410.php +++ b/migrations/Version20230108165410.php @@ -38,14 +38,18 @@ final class Version20230108165410 extends AbstractMultiPlatformMigration $this->addSql('ALTER TABLE project_bom_entries ADD CONSTRAINT FK_AFC547992F180363 FOREIGN KEY (id_device) REFERENCES projects (id)'); $this->addSql('ALTER TABLE project_bom_entries ADD CONSTRAINT FK_AFC54799C22F6CC4 FOREIGN KEY (id_part) REFERENCES parts (id)'); $this->addSql('ALTER TABLE projects DROP FOREIGN KEY FK_11074E9A6DEDCEC2'); - $this->addSql('ALTER TABLE projects DROP FOREIGN KEY devices_parent_id_fk'); + + //On old DBs migrated from the legacy Part-DB version the key devices_parent_id_fk is still existing + if ($this->getOldDBVersion() === 99) { + $this->addSql('ALTER TABLE projects DROP FOREIGN KEY devices_parent_id_fk'); + } $this->addSql('ALTER TABLE projects ADD status VARCHAR(64) DEFAULT NULL, ADD description LONGTEXT NOT NULL DEFAULT ""'); $this->addSql('DROP INDEX idx_11074e9a727aca70 ON projects'); $this->addSql('CREATE INDEX IDX_5C93B3A4727ACA70 ON projects (parent_id)'); $this->addSql('DROP INDEX idx_11074e9a6dedcec2 ON projects'); $this->addSql('CREATE INDEX IDX_5C93B3A46DEDCEC2 ON projects (id_preview_attachement)'); $this->addSql('ALTER TABLE projects ADD CONSTRAINT FK_11074E9A6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES attachments (id)'); - $this->addSql('ALTER TABLE projects ADD CONSTRAINT devices_parent_id_fk FOREIGN KEY (parent_id) REFERENCES projects (id)'); + $this->addSql('ALTER TABLE projects ADD CONSTRAINT FK_5C93B3A4727ACA70 FOREIGN KEY (parent_id) REFERENCES projects (id)'); } public function mySQLDown(Schema $schema): void