For some reason there are sometimes multiple or incorrectly named foreign keys on that column. This causes an issue when trying to remove the “unnamed” foreign key.
See https://www.woltlab.com/community/thread/302748-update-5-5-auf-6-0-x/
<instruction type="script" run="standalone">acp/update_com.woltlab.wcf_6.0_landingPage.php</instruction>
<!-- Migrate the database as early as possible. -->
- <instruction type="database" run="standalone">acp/database/update_com.woltlab.wcf_6.0_reaction_fk_step1.php</instruction>
+ <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_6.0_reaction_fk_step1.php</instruction>
<instruction type="database" run="standalone">acp/database/update_com.woltlab.wcf_6.0_reaction_fk_step2.php</instruction>
<instruction type="database" run="standalone">acp/database/update_com.woltlab.wcf_6.0.php</instruction>
+++ /dev/null
-<?php
-
-/**
- * Drops the reactionTypeID foreign key to later recreate it with the correct name.
- *
- * @author Tim Duesterhus
- * @copyright 2001-2022 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- */
-
-use wcf\system\database\table\index\DatabaseTableForeignKey;
-use wcf\system\database\table\PartialDatabaseTable;
-
-return [
- PartialDatabaseTable::create('wcf1_like')
- ->foreignKeys([
- DatabaseTableForeignKey::create()
- ->columns(['reactionTypeID'])
- ->referencedTable('wcf1_reaction_type')
- ->referencedColumns(['reactionTypeID'])
- ->onDelete('CASCADE')
- ->drop(),
- ]),
-];
--- /dev/null
+<?php
+
+namespace wcf\acp;
+
+/**
+ * Remove extraneous foreign keys on `wcf1_like.reactionTypeID` that use generic
+ * `*_ibfk` names
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+
+use wcf\system\WCF;
+
+$databaseEditor = WCF::getDB()->getEditor();
+$tableName = 'wcf' . WCF_N . '_like';
+foreach ($databaseEditor->getForeignKeys($tableName) as $foreignKey => $columnData) {
+ if ($columnData['columns'] !== ['reactionTypeID']) {
+ continue;
+ }
+
+ if ($columnData['referencedColumns'] !== ['reactionTypeID']) {
+ continue;
+ }
+
+ if ($columnData['referencedTable'] !== 'wcf' . WCF_N . '_reaction_type') {
+ continue;
+ }
+
+ $databaseEditor->dropForeignKey($tableName, $foreignKey);
+
+ $sql = "DELETE FROM wcf1_package_installation_sql_log
+ WHERE sqlTable = ?
+ AND sqlIndex = ?";
+ $statement = WCF::getDB()->prepare($sql);
+ $statement->execute([
+ $tableName,
+ $foreignKey,
+ ]);
+}