Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Phinx/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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,
);

Expand All @@ -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'];
}
}

Expand Down