laravel/framework · error · SQLiteDatabaseDoesNotExistException
Database file at path [{$path}] does not exist. Ensure this
Error message
Database file at path [{$path}] does not exist. Ensure this is an absolute path to the database. What it means
Thrown as Illuminate\Database\SQLiteDatabaseDoesNotExistException by SQLiteConnector::parseDatabasePath() when the SQLite file path cannot be resolved via realpath()/base_path(). Unlike most drivers, SQLite happily opens a non-existent file, so Laravel pre-checks and refuses to silently create the wrong database.
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 bd6b5437e6)
Solutions
- Create the database file first: touch database/database.sqlite, or run php artisan migrate with --force / answer 'yes' to the create prompt.
- Use an absolute path in DB_DATABASE (e.g. /var/www/app/database/database.sqlite).
- For tests or ephemeral runs, use DB_DATABASE=:memory:.
- Verify the path with is_file($path) at boot and create it if missing.
Example fix
// before (.env) DB_DATABASE=database.sqlite // relative; realpath() fails // after DB_DATABASE=/var/www/app/database/database.sqlite // or create it: // touch database/database.sqlite
Defensive patterns
Strategy: validation
Validate before calling
if (($driver ?? null) === 'sqlite' && $path !== ':memory:' && ! str_starts_with($path, 'file:') && ! is_file($path)) {
touch(dirname($path) ?: throw new \RuntimeException('Missing dir')) && touch($path);
} Type guard
function sqlitePathExistsOrInMemory(string $path): bool {
return $path === ':memory:'
|| str_contains($path, '?mode=memory')
|| str_contains($path, '&mode=memory')
|| str_starts_with($path, 'file:')
|| is_file($path);
} Try / catch
try {
DB::connection()->getPdo();
} catch (\Illuminate\Database\SQLiteDatabaseDoesNotExistException $e) {
@touch($e->path);
DB::purge();
DB::connection()->getPdo();
} Prevention
- Use absolute paths for DB_DATABASE with sqlite.
- Create the file in your deploy/CI script before migrating.
- Use :memory: for ephemeral/test runs.
- Ship an empty database.sqlite in the repo if appropriate.
When it happens
Trigger: Configuring a sqlite connection with a 'database' path that does not exist on disk and is not :memory: / a file: URI / a mode=memory DSN. Triggered on first connect (ConnectionFactory -> SQLiteConnector -> parseDatabasePath).
Common situations: Wrong/relative path in DB_DATABASE; the database file was deleted or never created; deploying to a fresh environment where database/database.sqlite wasn't shipped; typo'd path; running migrations before the SQLite file exists.
Related errors
- This driver does not support retrieving URLs.
- Unknown visibility: {$visibility}.
- Disk [{$name}] does not have a configured driver.
- Driver [{$driver}] is not supported.
- Scoped disk is missing "disk" configuration option.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/f9c126925e867797.json.
Report an issue: GitHub.