From df4765be6329fd1ef2bc4646c3923ef5e9907143 Mon Sep 17 00:00:00 2001 From: Josh Marshall Date: Fri, 22 May 2026 12:47:36 +1000 Subject: [PATCH] fix: MariaDB 12 uses numeric foreign keys by default --- src/Phinx/Db/Adapter/MysqlAdapter.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index 9753691f2..bc758f774 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -971,6 +971,7 @@ protected function getForeignKeys(string $tableName): array $tableName, )); foreach ($rows as $row) { + $foreignKeys[$row['CONSTRAINT_NAME']]['constraint'] = $row['CONSTRAINT_NAME']; $foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME']; $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME']; $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME']; @@ -999,7 +1000,7 @@ protected function getAddForeignKeyInstructions(Table $table, ForeignKey $foreig protected function getDropForeignKeyInstructions(string $tableName, string $constraint): AlterInstructions { $alter = sprintf( - 'DROP FOREIGN KEY %s', + 'DROP FOREIGN KEY `%s`', $constraint, ); @@ -1019,9 +1020,9 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr $matches = []; $foreignKeys = $this->getForeignKeys($tableName); - foreach ($foreignKeys as $name => $key) { - if (array_map('mb_strtolower', $key['columns']) === $columns) { - $matches[] = $name; + foreach ($foreignKeys as $foreignKey) { + if (array_map('mb_strtolower', $foreignKey['columns']) === $columns) { + $matches[] = $foreignKey['constraint']; } }