Skip to content Skip to sidebar Skip to footer

How To Make Sqlite Work In Laravel

Whenever I run php artisan migrate, the following error is shown in the console: [PDOException] SQLSTATE[HY000] [14] unable to open database file The database.sqlite file is

Solution 1:

Short Solution

Though not answering the question, the way to fix "Database not found" issue is to replace the following line in database.php:

'database' => env('DB_DATABASE', database_path('database.sqlite')),

with

'database' => database_path('database.sqlite'),

Solution 2:

By using the relative path, migrations will fail because they use project directory as root directory...

To correct everything, I suggest setting:

DB_DATABASE=database\database.sqlite

and tweaking the sqlite connections in config/database.php as follows:

'database' => env('DB_DATABASE/..', database_path('database.sqlite')),

Original Answer

The .env file should contain this:

DB_DATABASE=..\database\database.sqlite

With some testing you can verify that the link included in DB_DATABASE is relative to the 'public' directory (at least on my Windows machine). That's why we should introduce ..\ before your link.

And of course, using an absolute link should do it too:

DB_DATABASE=D:\www\project\database\database.sqlite 

as @Josh suggests

Solution 3:

Complementing the awnser by our friend @alexander-lomia

Change:

'database' => env('DB_DATABASE', database_path('database.sqlite'))

To:

'database' => database_path(env('DB_DATABASE'))

in database.php

:)

Solution 4:

  1. Create file called database.sqlite in this folder as database/database.sqlite

  2. Open the .env file and change MySQL to SQLite

  3. Comment password and username and databaseName using '#'

  4. run php artisan migrate enjoy

env file like this:

DB_CONNECTION=sqlite

#DB_HOST=127.0.0.1#DB_PORT=3306#DB_DATABASE=database#DB_USERNAME=homestead#DB_PASSWORD=secret

Solution 5:

Instead of a relative path you need to use an absolute path in your .env file.

DB_DATABASE=/var/www/project/database/database.sqlite

or in your case:

DB_DATABASE=D:\www\project\database\database.sqlite

Post a Comment for "How To Make Sqlite Work In Laravel"