Laravel "Database file at path database.sqlite does not exist" error
How to resolve the 'Database file at path database.sqlite does not exist' error in Laravel and set up SQLite correctly on both Unix-based systems and Windows.
The "Database file at path database.sqlite does not exist"
error in Laravel occurs when your application is configured to use SQLite (default in Laravel 11), but the database file isn't where it should be. Let's fix this.
Why This Happens
Common reasons:
- The SQLite database file hasn't been created yet.
- The file path in your configuration is incorrect.
- The directory permissions are preventing Laravel from accessing or creating the file.
Quick Fix
Here's how to resolve it:
1. Check your .env
file
Ensure it contains:
DB_CONNECTION=sqlite
2. Create the SQLite database file
Unix-based systems (macOS, Linux):
touch database/database.sqlite
Windows (Command Prompt):
type nul > database\database.sqlite
Windows (PowerShell):
New-Item -Path "database\database.sqlite" -ItemType File
3. Update database config if needed
In config/database.php
, verify the sqlite
connection:
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
4. Set the correct permissions
Unix-based systems:
chmod 644 database/database.sqlite
Windows: Right-click the file, go to Properties -> Security -> Edit -> Add, type in your username, click Check Names, then OK. Give yourself Read & Write permissions.
5. Run migrations
php artisan migrate
Troubleshooting
If you're still encountering issues:
- Ensure PHP has SQLite support enabled.
- Check that the database directory is writable by your web server.
- Verify your Laravel version and update if necessary.
- On Windows, make sure your path uses forward slashes (/) or escaped backslashes (\) in your PHP configurations.