Skip to content

Commit 68e1a4d

Browse files
fix: MariaDB 12 uses numeric foreign keys by default (#2413)
1 parent 304084e commit 68e1a4d

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/Phinx/Db/Adapter/MysqlAdapter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ protected function getForeignKeys(string $tableName): array
971971
$tableName,
972972
));
973973
foreach ($rows as $row) {
974+
$foreignKeys[$row['CONSTRAINT_NAME']]['constraint'] = $row['CONSTRAINT_NAME'];
974975
$foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME'];
975976
$foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME'];
976977
$foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME'];
@@ -999,7 +1000,7 @@ protected function getAddForeignKeyInstructions(Table $table, ForeignKey $foreig
9991000
protected function getDropForeignKeyInstructions(string $tableName, string $constraint): AlterInstructions
10001001
{
10011002
$alter = sprintf(
1002-
'DROP FOREIGN KEY %s',
1003+
'DROP FOREIGN KEY `%s`',
10031004
$constraint,
10041005
);
10051006

@@ -1019,9 +1020,9 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr
10191020

10201021
$matches = [];
10211022
$foreignKeys = $this->getForeignKeys($tableName);
1022-
foreach ($foreignKeys as $name => $key) {
1023-
if (array_map('mb_strtolower', $key['columns']) === $columns) {
1024-
$matches[] = $name;
1023+
foreach ($foreignKeys as $foreignKey) {
1024+
if (array_map('mb_strtolower', $foreignKey['columns']) === $columns) {
1025+
$matches[] = $foreignKey['constraint'];
10251026
}
10261027
}
10271028

0 commit comments

Comments
 (0)