diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index d61d324c934..952ed821656 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -304,14 +304,15 @@ private function reverseEngineerMappingFromDatabase(): void $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns()); } - if (! $table->hasPrimaryKey()) { + $primaryKey = $table->getPrimaryKey(); + if ($primaryKey === null) { throw new MappingException( 'Table ' . $tableName . ' has no primary key. Doctrine does not ' . "support reverse engineering from tables that don't have a primary key." ); } - $pkColumns = $table->getPrimaryKey()->getColumns(); + $pkColumns = $primaryKey->getColumns(); sort($pkColumns); sort($allForeignKeyColumns); diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 81602852e11..d011e8ecc18 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -893,13 +893,16 @@ public function getDropSchemaSQL(array $classes) } foreach ($schema->getTables() as $table) { - if ($table->hasPrimaryKey()) { - $columns = $table->getPrimaryKey()->getColumns(); - if (count($columns) === 1) { - $checkSequence = $table->getName() . '_' . $columns[0] . '_seq'; - if ($deployedSchema->hasSequence($checkSequence) && ! $schema->hasSequence($checkSequence)) { - $schema->createSequence($checkSequence); - } + $primaryKey = $table->getPrimaryKey(); + if ($primaryKey === null) { + continue; + } + + $columns = $primaryKey->getColumns(); + if (count($columns) === 1) { + $checkSequence = $table->getName() . '_' . $columns[0] . '_seq'; + if ($deployedSchema->hasSequence($checkSequence) && ! $schema->hasSequence($checkSequence)) { + $schema->createSequence($checkSequence); } } }