flarum/framework · error · ValidationFailed

Please specify a database driver.

Error message

Please specify a database driver.

What it means

DatabaseConfig::validate() requires a non-empty driver during construction. An empty driver means the installer could not determine which database type to configure, so ValidationFailed('Please specify a database driver.') is thrown.

Solutions

  1. Set the driver explicitly to one of: mysql, mariadb, sqlite, pgsql
  2. Add the missing driver key to the install configuration file
  3. Re-run the installer interactively so the driver prompt is answered

Example fix

// before
$configuration = ['host' => 'localhost', 'database' => 'forum'];
// after
$configuration = ['driver' => 'mysql', 'host' => 'localhost', 'database' => 'forum'];
Defensive patterns

Strategy: validation

Validate before calling

if (empty($configuration['driver'])) {
    throw new ValidationFailed('Please specify a database driver.');
}

Try / catch

try {
    $dbConfig = new DatabaseConfig($configuration);
} catch (ValidationFailed $e) {
    $output->writeln("<error>{$e->getMessage()}</error>");
    return Command::FAILURE;
}

Prevention

When it happens

Trigger: Constructing DatabaseConfig with driver '' or null; install input missing the 'driver' key so it defaults to empty.

Common situations: Automated/headless installs whose config file omits the database driver; interactive installs where the driver prompt value was dropped; copy-pasted config templates with the driver line removed.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/89af38fa261ebad2. Report an issue: GitHub.

Appendix: source

Thrown at framework/core/src/Install/DatabaseConfig.php:44

        private readonly ?string $prefix
    ) {
        $this->validate();
    }

    public function toArray(): array
    {
        return array_merge([
            'driver' => $this->driver,
            'database' => $this->database,
            'prefix' => $this->prefix,
            'prefix_indexes' => true
        ], $this->driverOptions());
    }

    private function validate(): void
    {
        if (empty($this->driver)) {
            throw new ValidationFailed('Please specify a database driver.');
        }

        if (! in_array($this->driver, ['mysql', 'mariadb', 'sqlite', 'pgsql'])) {
            throw new ValidationFailed('Currently, only MySQL, MariaDB, SQLite and PostgreSQL are supported.');
        }

        if (empty($this->host) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) {
            throw new ValidationFailed('Please specify the hostname of your database server.');
        }

        if (($this->port < 1 || $this->port > 65535) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) {
            throw new ValidationFailed('Please provide a valid port number between 1 and 65535.');
        }

        if (empty($this->database)) {
            throw new ValidationFailed('Please specify the database name.');
        }

View on GitHub (pinned to 4b939f6853)