Skip to content
Latchkey

Laravel "Database file ... does not exist" (sqlite) in CI

With the sqlite connection Laravel expects the database file to already exist on disk. A fresh checkout has no database/database.sqlite, so it aborts. Create the file with touch (or use an in-memory database) before running migrations.

What this error means

Migrate fails with "Database file at path [database/database.sqlite] does not exist. Ensure this is an absolute path to the database." because the sqlite file was never created.

php artisan
  SQLSTATE[HY000] [14] unable to open database file
  Database file at path [database/database.sqlite] does not exist.
  Ensure this is an absolute path to the database.

Common causes

The sqlite file was never created in CI

The sqlite driver does not create the file for you. A fresh clone has no database/database.sqlite, so opening it fails.

A relative path resolved from the wrong directory

A relative DB_DATABASE path is resolved against the working directory; if the step runs elsewhere, the file is not found.

How to fix it

Create the sqlite file before migrating

  1. Create the file with touch database/database.sqlite.
  2. Point DB_CONNECTION at sqlite and DB_DATABASE at that path.
  3. Run migrations against the now-existing file.
.github/workflows/ci.yml
- run: touch database/database.sqlite
- run: php artisan migrate --force
env:
  DB_CONNECTION: sqlite
  DB_DATABASE: database/database.sqlite

Use an in-memory sqlite database

For tests, :memory: needs no file at all and is faster; set it in phpunit.xml.

phpunit.xml
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

How to prevent it

  • Run touch database/database.sqlite before migrate when using file sqlite.
  • Prefer :memory: for the test suite.
  • Use absolute paths for DB_DATABASE when steps change directories.

Frequently asked questions

What causes ""Database file ... does not exist""?
The sqlite driver does not create the file for you. A fresh clone has no database/database.sqlite, so opening it fails.
How do I fix "Database file ... does not exist"?
Create the sqlite file before migrating

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card