From: Michael Date: Sat, 16 May 2020 20:57:04 +0000 (+0000) Subject: Issue 8635: Create foreign keys without constraint name X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ecde6b0066f084b00450aa0c8bced2cbc6a86af1;p=friendica.git Issue 8635: Create foreign keys without constraint name --- diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index e75e2f58cc..b16879e9cc 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -483,8 +483,8 @@ class DBStructure } } - foreach ($existing_foreign_keys as $constraint => $param) { - $sql2 = self::dropForeignKey($constraint); + foreach ($existing_foreign_keys as $param) { + $sql2 = self::dropForeignKey($param['CONSTRAINT_NAME']); if ($sql3 == "") { $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2; @@ -693,8 +693,8 @@ class DBStructure if (DBA::isResult($foreign_keys)) { foreach ($foreign_keys as $foreign_key) { - $constraint = $foreign_key['CONSTRAINT_NAME']; - unset($foreign_key['CONSTRAINT_NAME']); + $parameters = ['foreign' => [$foreign_key['REFERENCED_TABLE_NAME'] => $foreign_key['REFERENCED_COLUMN_NAME']]]; + $constraint = self::getConstraintName($table, $foreign_key['COLUMN_NAME'], $parameters); $foreigndata[$constraint] = $foreign_key; } } @@ -783,10 +783,7 @@ class DBStructure $foreign_table = array_keys($parameters['foreign'])[0]; $foreign_field = array_values($parameters['foreign'])[0]; - $constraint = self::getConstraintName($tablename, $fieldname, $parameters); - - $sql = "CONSTRAINT `" . $constraint . "` FOREIGN KEY (`" . $fieldname . "`)" . - " REFERENCES `" . $foreign_table . "` (`" . $foreign_field . "`)"; + $sql = "FOREIGN KEY (`" . $fieldname . "`) REFERENCES `" . $foreign_table . "` (`" . $foreign_field . "`)"; if (!empty($parameters['foreign']['on update'])) { $sql .= " ON UPDATE " . strtoupper($parameters['foreign']['on update']);