CN

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:

  1. The SQLite database file hasn't been created yet.
  2. The file path in your configuration is incorrect.
  3. 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:

.env
DB_CONNECTION=sqlite

2. Create the SQLite database file

Unix-based systems (macOS, Linux):

Run in Terminal/Command Prompt
touch database/database.sqlite

Windows (Command Prompt):

Run in Terminal/Command Prompt
type nul > database\database.sqlite

Windows (PowerShell):

Run in Terminal/Command Prompt
New-Item -Path "database\database.sqlite" -ItemType File

3. Update database config if needed

In config/database.php, verify the sqlite connection:

config/database.php
'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:

Run in Terminal/Command Prompt
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

Run in Terminal/Command Prompt
php artisan migrate

Troubleshooting

If you're still encountering issues:

  1. Ensure PHP has SQLite support enabled.
  2. Check that the database directory is writable by your web server.
  3. Verify your Laravel version and update if necessary.
  4. On Windows, make sure your path uses forward slashes (/) or escaped backslashes (\) in your PHP configurations.
Want to read more articles like that?

Sign up to get notified when I publish more.

No spam. One click unsubscribe.

Read More on Fado Code Camp