diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index f73dd51e9b4..05859bd66f6 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -317,6 +317,10 @@ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint return true; } + if (strtolower($key1->getForeignTableName()) != strtolower($key2->getForeignTableName())) { + return true; + } + if ($key1->onUpdate() != $key2->onUpdate()) { return true; } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 5301bd8e96e..4e6e8f9b465 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -486,6 +486,29 @@ public function testTableUpdateForeignKey() $this->assertEquals(1, count($tableDiff->changedForeignKeys)); } + public function testMovedForeignKeyForeignTable() + { + $tableForeign = new Table("bar"); + $tableForeign->addColumn('id', 'integer'); + + $tableForeign2 = new Table("bar2"); + $tableForeign2->addColumn('id', 'integer'); + + $table1 = new Table("foo"); + $table1->addColumn('fk', 'integer'); + $table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + + $table2 = new Table("foo"); + $table2->addColumn('fk', 'integer'); + $table2->addForeignKeyConstraint($tableForeign2, array('fk'), array('id')); + + $c = new Comparator(); + $tableDiff = $c->diffTable($table1, $table2); + + $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + $this->assertEquals(1, count($tableDiff->changedForeignKeys)); + } + public function testTablesCaseInsensitive() { $schemaA = new Schema();