diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 48b7dc892a1..08bb895fbd9 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -289,8 +289,8 @@ public function diffTable(Table $table1, Table $table2) // only named foreign key constraints can change, otherwise it appears as removed+added. if ( - $constraint1->getName() && - $constraint2->getName() && + strlen($constraint1->getName()) > 0 && + strlen($constraint2->getName()) > 0 && strtolower($constraint1->getName()) === strtolower($constraint2->getName()) ) { $tableDifferences->changedForeignKeys[] = $constraint2; diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 7fce852172c..705392944a9 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -406,10 +406,9 @@ protected function _getPortableViewDefinition($view) protected function _getPortableTableForeignKeysList($tableForeignKeys) { $list = []; - $i = 0; foreach ($tableForeignKeys as $value) { $value = array_change_key_case($value, CASE_LOWER); - $index = $value['constraint_name'] ?: $i++; + $index = $value['constraint_name'] ?? $value['id']; if (! isset($list[$index])) { if (! isset($value['on_delete']) || $value['on_delete'] === 'RESTRICT') { $value['on_delete'] = null; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index e832683dc67..2f0511c0f3c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -261,35 +261,34 @@ public function testOnlyOwnCommentIsParsed(): void public function testUnnamedForeignKeyConstraintHandling(): void { $sql = <<connection->exec($sql); $sm = $this->connection->getSchemaManager(); - $onlineTable = $sm->listTableDetails('bug4243_documents'); + $onlineTable = $sm->listTableDetails('unnamedfk_referencing'); - $offlineTable = new Table('bug4243_documents'); + $offlineTable = new Table('unnamedfk_referencing'); $offlineTable->addColumn('id', 'integer'); + $offlineTable->addColumn('reference1_id1', 'integer'); + $offlineTable->addColumn('reference1_id2', 'integer'); + $offlineTable->addColumn('reference2_id', 'integer'); $comparator = new Schema\Comparator(); $diff = $comparator->diffTable($offlineTable, $onlineTable); @@ -300,7 +299,7 @@ public function testUnnamedForeignKeyConstraintHandling(): void $this->connection->exec($sql); } - $onlineTableAfter = $sm->listTableDetails('bug4243_documents'); + $onlineTableAfter = $sm->listTableDetails('unnamedfk_referencing'); $diff = $comparator->diffTable($onlineTable, $onlineTableAfter); $this->assertFalse($diff);