From fe66d8bc04de42ab13b83892df11a5ea1533b544 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Tue, 26 Apr 2011 12:32:04 -0300 Subject: [PATCH] Fixed SchemaTool which was failing to dropSchema due to foreignKeyContraint checks. Fixes DDC-1126 --- lib/Doctrine/ORM/Tools/SchemaTool.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 1edbd38a1..f1358708b 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -598,7 +598,11 @@ class SchemaTool */ public function getDropSchemaSQL(array $classes) { - $sm = $this->_em->getConnection()->getSchemaManager(); + /* @var $conn \Doctrine\DBAL\Connection */ + $conn = $this->_em->getConnection(); + + /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + $sm = $conn->getSchemaManager(); $sql = array(); $orderedTables = array(); @@ -633,13 +637,18 @@ class SchemaTool } } + $supportsForeignKeyConstraints = $conn->getDatabasePlatform()->supportsForeignKeyConstraints(); $dropTablesSql = array(); + foreach ($orderedTables AS $tableName) { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $foreignKeys = $sm->listTableForeignKeys($tableName); - foreach ($foreignKeys AS $foreignKey) { - $sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName); + if ($supportsForeignKeyConstraints) { + $foreignKeys = $sm->listTableForeignKeys($tableName); + + foreach ($foreignKeys AS $foreignKey) { + $sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName); + } } + $dropTablesSql[] = $this->_platform->getDropTableSQL($tableName); }