SQLite unable to open database file: Laravel + Windows
Solution 1
try to remove the DB_DATABASE="yourdatabase" variable in your .env file
Solution 2
If the permissions allow to write on the folder just create the storage folders.
e-g, this how I fix the problem.
in config/database.php
:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database/databaseName.sqlite'),
'prefix' => '',
],
Then if you run on your terminal php artisan migrate
, it returns you the [PDOException] SQLSTATE[HY000] [14] unable to open database file
Create the path folder by your own, e-g in your terminal mkdir storage/database/databaseName.sqlite
Make sure the permissions allow you to write, then re-run the command php artisan migrate
, it returns you the success message : Migration table created successfully
.
Solution 3
On laravel 5.3.x
This was the only thing that worked for me:
Change DB_CONNECTION from "mysql" to "sqlite". Because this is an sqlite database, you can delete all the other DB_* items in that .env file.
APP_ENV=local APP_KEY=base64: APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost
DB_CONNECTION=sqlite
Solution 4
You just need to make sqlite file available at the defined path. In larvel 5.7, I just used following command and run migration.
touch /absolute/path/of/db.sqlite
That will create an empty file at defined location and you are good to go.
Observation: In Larvel 5.7, .sqlite file should be already available at defined location.
For windows, right click and create new file with the defined name at defined location.
Solution 5
Well it may be late but I have also faced the problem in ubuntu
environment, here exactly how I overcome this issue.
You have to pass your fully qualified sqlite
file's path to your .env
file, like following:
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="/var/www/html/my-awesome-project/database/database.sqlite"
DB_USERNAME=homestead
DB_PASSWORD=secret
Here change the value of DB_DATABASE
key to the exact location of your sqlite
file in your computer's filesystem.
Tips:
You can find your database's path for sqlite
file by adding
dd(database_path('database.sqlite'));
this line of code in the top of config/database.php
file and run php artisan migrate
to terminal. You can find the exact location from there, copy it and put it to .env
s DB_DATABASE
key.
Don't forget to restart laravel server and remove dd(database_path('database.sqlite'));
form database.php
before testing.
Comments
-
Miguel Borges almost 2 years
I'm try use a sqlite database in my laravel project, in local environment for dev (Windows 8.1 with AMMPS), but when I try run a
migrate:instal
command, this error apeear:[PDOException] SQLSTATE[HY000] [14] unable to open database file
My database config file (app/config/local/database.php):
<?php return array( 'default' => 'sqlite', 'connections' => array( 'sqlite' => array( 'driver' => 'sqlite', 'database' => __DIR__ . '\..\..\database\production.sqlite', 'prefix' => '', ), ), );
-
SEsterbauer over 7 years@JakubKopyś Because the
.env
file's values are loaded fromconfig/database.php
as long as the keys are listed inside, no matter what their value is. If a key is not found in the.env
file, it defaults to the value set inconfig/database.php
, which would be.../database/database.sqlite
in the case ofDB_DATABASE
(as of Laravel 5.3)