I created my database.sqlite file in the database folder. My .env file contents are :
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=absolute\path\to\database\database.sqlite
DB_USERNAME=admin
DB_PASSWORD=
When I run php artisan tinker and DB::table('users')->get(); I get the info from the database.
My DatabaseController is:
class DatabaseController extends Controller
{
public function main()
{
$users = DB::table('users')->get();
return view('database',compact($users));
}
}
Yet when I request /database path I get the error:
QueryException in Connection.php line 647:
Database (database/database.sqlite) does not exist. (SQL: select * from "users")
UPDATE:
A temporary fix is to change the database.php from the config folder:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => 'absolute\path\database\database.sqlite',
'prefix' => '',
],
Instead of using env('DB_DATABASE', database_path('database.sqlite')), which returns database/database.sqlite not my absolute path.
You need to use full path, something like:
DB_DATABASE=/home/laravel-project/database/database.sqlite
If you remove DB_DATABASE=... from your .env file and use the path in the config/database.php:
'database' => env('DB_DATABASE', database_path('database.sqlite')),...
(if your database.sqlite file is in database/ folder), it will work, too.
I ran the following commands:
php artisan config:cache
php artisan config:clear
php artisan serve - restarted the server
In config/database.php file:
'sqlite' => [
'driver' => 'sqlite',
'database' => dirname(__DIR__).'/database/database.sqlite',
],
Then run following command:
php artisan config:cache
php artisan config:clear
I think, that the problem here was because of Homestead. Absolute path to the database.sqlite file on local machine is not the same as the virtual machine one has.
In my case a had to set:
DB_DATABASE=/home/vagrant/code/database/database.sqlite
Or, you can just comment out this line and you are ready to go.
#DB_DATABASE=
For those who still face this issue: https://laracasts.com/discuss/channels/general-discussion/database-databasedatabasesqlite-does-not-exist-error-on-running?page=1
Since sqlite only require DB_CONNECTION=sqlite in .env file so you just remove the other:
DB_HOST
DB_PORT
DB_DATABASE
DB_USERNAME
DB_PASSWORD
then save and run migration again. This was how I solved the problem. Cheers!
来源:https://stackoverflow.com/questions/43140711/database-database-database-sqlite-does-not-exist-database-works-from-artisan