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.
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
- Create the file with
touch database/database.sqlite. - Point DB_CONNECTION at sqlite and DB_DATABASE at that path.
- Run migrations against the now-existing file.
- run: touch database/database.sqlite
- run: php artisan migrate --force
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqliteUse an in-memory sqlite database
For tests, :memory: needs no file at all and is faster; set it in phpunit.xml.
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>How to prevent it
- Run
touch database/database.sqlitebefore migrate when using file sqlite. - Prefer
:memory:for the test suite. - Use absolute paths for DB_DATABASE when steps change directories.