diff --git a/UPGRADE.md b/UPGRADE.md index 1af030762a0..9ebb0b54ed9 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -13,6 +13,11 @@ awareness about deprecated code. The `AbstractPlatform::supportsForeignKeyConstraints()` method has been deprecated. All platforms should support foreign key constraints. +## Deprecated `AbstractPlatform::supportsForeignKeyConstraints()`. + +Relying on the DBAL not generating DDL for foreign keys on MySQL engines other than InnoDB is deprecated. +Define foreign key constraints only if they are necessary. + ## Deprecated `AbstractPlatform` methods exposing quote characters. The `AbstractPlatform::getStringLiteralQuoteCharacter()` and `::getIdentifierQuoteCharacter()` methods diff --git a/src/Platforms/AbstractMySQLPlatform.php b/src/Platforms/AbstractMySQLPlatform.php index 09828c977e9..35e36c5a5f0 100644 --- a/src/Platforms/AbstractMySQLPlatform.php +++ b/src/Platforms/AbstractMySQLPlatform.php @@ -451,9 +451,18 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] } // Propagate foreign key constraints only for InnoDB. - if (isset($options['foreignKeys']) && $engine === 'INNODB') { - foreach ($options['foreignKeys'] as $definition) { - $sql[] = $this->getCreateForeignKeySQL($definition, $name); + if (isset($options['foreignKeys'])) { + if ($engine === 'INNODB') { + foreach ($options['foreignKeys'] as $definition) { + $sql[] = $this->getCreateForeignKeySQL($definition, $name); + } + } elseif (count($options['foreignKeys']) > 0) { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pulls/5414', + 'Relying on the DBAL not generating DDL for foreign keys on MySQL engines' + . ' other than InnoDB is deprecated. Define foreign key constraints only if they are necessary.' + ); } }