diff --git a/app/Controllers/Setup.php b/app/Controllers/Setup.php index a63c481..6cd33bc 100644 --- a/app/Controllers/Setup.php +++ b/app/Controllers/Setup.php @@ -773,7 +773,7 @@ class Setup extends BaseController foreach ($pending as $stmt) { $message = (string) ($deferredLastErrors[$stmt] ?? 'Unresolved FK dependency after retries'); - if ($this->isCreateTableStatement($stmt) && stripos($message, 'cannot add foreign key constraint') !== false) { + if ($this->canRetryCreateTableWithoutForeignKeys($stmt, $message)) { $retry = $this->stripForeignKeysFromCreateTable($stmt); if ($retry !== $stmt && $retry !== '') { try { @@ -1707,6 +1707,33 @@ class Setup extends BaseController return false; } + private function canRetryCreateTableWithoutForeignKeys(string $stmt, string $message): bool + { + if (!$this->isCreateTableStatement($stmt)) { + return false; + } + + $messageLower = strtolower($message); + + if (str_contains($messageLower, 'cannot add foreign key constraint')) { + return true; + } + + if (str_contains($messageLower, 'failed to open the referenced table')) { + return true; + } + + if (str_contains($messageLower, 'foreign key constraint is incorrectly formed')) { + return true; + } + + if (str_contains($messageLower, 'errno: 150')) { + return true; + } + + return false; + } + /** * @param array $idxDef * @param array> $clientCols