{"record":{"id":"7f096660cc8051bd","repo":"flarum/framework","slug":"the-prefix-should-be-no-longer-than-maxprefix-characters-on","errorCode":null,"errorMessage":"The prefix should be no longer than $maxPrefix characters on $this->driver.","messagePattern":"The prefix should be no longer than \\$maxPrefix characters on \\$this->driver\\.","errorType":"validation","errorClass":"ValidationFailed","httpStatus":null,"severity":"error","filePath":"framework/core/src/Install/DatabaseConfig.php","lineNumber":79,"sourceCode":"        }\n\n        if (empty($this->schema) && $this->driver == 'pgsql') {\n            throw new ValidationFailed('Please specify the schema name.');\n        }\n\n        if (empty($this->username) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) {\n            throw new ValidationFailed('Please specify the username for accessing the database.');\n        }\n\n        if (! empty($this->prefix)) {\n            if (! preg_match('/^[\\pL\\pM\\pN_]+$/u', $this->prefix)) {\n                throw new ValidationFailed('The prefix may only contain characters and underscores.');\n            }\n\n            $maxPrefix = DatabaseRequirements::maxTablePrefixLength($this->driver);\n\n            if ($maxPrefix !== null && strlen($this->prefix) > $maxPrefix) {\n                throw new ValidationFailed(\"The prefix should be no longer than $maxPrefix characters on $this->driver.\");\n            }\n        }\n    }\n\n    public function prepare(Paths $paths): void\n    {\n        if ($this->driver === 'sqlite' && ! file_exists($this->database)) {\n            $this->database = str_replace('.sqlite', '', $this->database).'.sqlite';\n            touch($paths->base.'/'.$this->database);\n        }\n    }\n\n    private function driverOptions(): array\n    {\n        return match ($this->driver) {\n            'mysql', 'mariadb' => [\n                'host' => $this->host,\n                'port' => $this->port,","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Install/DatabaseConfig.php#L61-L97","documentation":"ValidationFailed thrown by DatabaseConfig::validate when the prefix is longer than the maximum identifier length the driver allows, as computed by DatabaseRequirements::maxTablePrefixLength(). Long prefixes plus table names can exceed database identifier limits (e.g. MySQL's 64-character names).","triggerScenarios":"Setting a prefix whose strlen() exceeds the driver-specific cap, e.g. a 30+ character prefix on MySQL where the driver limit is 10 or similar.","commonSituations":"Users pasting long descriptive prefixes like 'mycompany_project_environment_'; generated prefixes from long app names; changing drivers without rechecking the limit (limits differ per driver).","solutions":["Shorten the prefix below the driver's maxTablePrefixLength, e.g. 'app_'.","Query DatabaseRequirements::maxTablePrefixLength($driver) and truncate the prefix with substr() to that limit.","Remove the prefix entirely if multi-tenancy is handled another way."],"exampleFix":"// before\n$max = DatabaseRequirements::maxTablePrefixLength($driver);\n$config = new DatabaseConfig(driver: $driver, ..., prefix: 'very_long_company_project_prefix_');\n// after\n$max = DatabaseRequirements::maxTablePrefixLength($driver);\n$prefix = mb_substr('very_long_company_project_prefix_', 0, $max);\n$config = new DatabaseConfig(driver: $driver, ..., prefix: $prefix);","handlingStrategy":"validation","validationCode":"$max = DatabaseRequirements::maxTablePrefixLength($driver);\nif ($max !== null && strlen($prefix) > $max) {\n    $prefix = substr($prefix, 0, $max);\n}\n$config = new DatabaseConfig(driver: $driver, ..., prefix: $prefix);","typeGuard":"function prefixFits(string $prefix, string $driver): bool {\n    $max = DatabaseRequirements::maxTablePrefixLength($driver);\n    return $max === null || strlen($prefix) <= $max;\n}","tryCatchPattern":"try {\n    $config = new DatabaseConfig(...$input);\n} catch (ValidationFailed $e) {\n    if (str_contains($e->getMessage(), 'no longer than')) {\n        $errors['prefix'] = 'Shorten the prefix for this driver.';\n    }\n}","preventionTips":["Always truncate prefix input to maxTablePrefixLength in the UI.","Set maxlength on the prefix form field per driver.","Recheck the limit whenever the driver changes."],"tags":["database","prefix","identifier-length","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}