laravel/framework · error · SQLiteDatabaseDoesNotExistException

Database file at path

Error message

Database file at path [{$path}] does not exist. Ensure this is an absolute path to the database.

What it means

Thrown as SQLiteDatabaseDoesNotExistException by SQLiteConnector::parseDatabasePath() when realpath() cannot resolve the configured path (and base_path() relative resolution also fails). Laravel refuses to silently create an arbitrary SQLite file at connection time, so it surfaces the missing path explicitly. In-memory databases (:memory:, ?mode=memory, &mode=memory) and file: URIs are exempt.

Solutions

  1. Create the file before connecting: touch database/database.sqlite (or run php artisan migrate which will offer to create it).
  2. Set the path correctly in .env: DB_DATABASE=/absolute/path/to/database.sqlite.
  3. Use :memory: for ephemeral/test databases.
  4. Ensure the directory exists and is writable so the file can be created by migrations.

Example fix

// before
// .env: DB_DATABASE=nonexistent.sqlite

// after
touch database/database.sqlite
// .env: DB_DATABASE=/var/www/html/database/database.sqlite
Defensive patterns

Strategy: validation

Validate before calling

if ($config['driver'] === 'sqlite'
    && ! in_array($config['database'], [':memory:'], true)
    && ! str_starts_with($config['database'], 'file:')
    && ! str_contains($config['database'], 'mode=memory')
    && ! file_exists($config['database'])) {
    throw new \Illuminate\Database\SQLiteDatabaseDoesNotExistException($config['database']);
}

Type guard

function sqliteDatabaseExists(string $path): bool {
    return $path === ':memory:'
        || str_starts_with($path, 'file:')
        || str_contains($path, 'mode=memory')
        || file_exists($path);
}

Try / catch

try {
    DB::connection()->getPdo();
} catch (\Illuminate\Database\SQLiteDatabaseDoesNotExistException $e) {
    touch(database_path('database.sqlite'));
    DB::reconnect();
}

Prevention

When it happens

Trigger: Configuring a sqlite connection whose 'database' path does not exist on disk and is not an in-memory/URI form. Fires the first time the connection is opened (DB::connection, a migration, a model query).

Common situations: First run before migrations create database/database.sqlite; relative path that does not resolve from the working directory; deployed app where the database file was not included/created; typo in DB_DATABASE; running tests without first touching the test sqlite file.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/f9c126925e867797. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Database/Connectors/SQLiteConnector.php:61

        // SQLite supports "in-memory" databases that only last as long as the owning
        // connection does. These are useful for tests or for short lifetime store
        // querying. In-memory databases shall be anonymous (:memory:) or named.
        if ($path === ':memory:' ||
            str_contains($path, '?mode=memory') ||
            str_contains($path, '&mode=memory') ||
            str_starts_with($path, 'file:')
        ) {
            return $path;
        }

        $path = realpath($path) ?: (function_exists('base_path') ? realpath(base_path($path)) : false);

        // Here we'll verify that the SQLite database exists before going any further
        // as the developer probably wants to know if the database exists and this
        // SQLite driver will not throw any exception if it does not by default.
        if ($path === false) {
            throw new SQLiteDatabaseDoesNotExistException($database);
        }

        return $path;
    }

    /**
     * Set miscellaneous user-configured pragmas.
     *
     * @param  \PDO  $connection
     * @param  array  $config
     * @return void
     */
    protected function configurePragmas($connection, array $config): void
    {
        if (! isset($config['pragmas'])) {
            return;
        }

View on GitHub (pinned to e0f6eb3518)