SQLiteConnector.php 第 34 行中的 InvalidArgumentException:数据库 (homestead) 不存在
InvalidArgumentException in SQLiteConnector.php line 34: Database (homestead) does not exist
我正在 Laracasts 中从头开始学习系列 Laravel 5,具体来说,我正在上课 "Fetching Data"。
我创建了 database.sqlite 文件,我从 tinker 添加了一些数据,并能够在控制台中检索它们。然后,我尝试复制视频的内容。
我的卡片控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
class CardsController extends Controller
{
public function index()
{
$cards = \DB::table('cards')->get();
return view('cards.index', compact('cards'));
}
}
但是,当我尝试加载 /cards 路由时出现以下错误
InvalidArgumentException in SQLiteConnector.php line 34:
Database (homestead) does not exist.
这是我的 env
文件
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:P3ZgRMRkb2e8+x7S9rDLLB+bKJdR5Unpj8zXBUIHIZE=
APP_URL=http://localhost
DB_CONNECTION=sqlite
DB_FILE=database.sqlite
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
在您的错误中引用的那一行下面是:
// Here we'll verify that the SQLite database exists before going any further
// as the developer probably wants to know if the database exists and this
// SQLite driver will not throw any exception if it does not by default.
if ($path === false) {
throw new InvalidArgumentException("Database (${config['database']}) does not exist.");
}
看方法上面的注释,好像你的路径设置不正确。我相信正确的环境变量应该是:
DB_DATABASE=database/database.sqlite
而不是
DB_FILE=database/database.sqlite
如果没有,请检查您的 config/database.php
文件,并查找以下部分:
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')), // this line!
'prefix' => '',
],
我刚刚也注意到(至少在 Laravel 版本 5.2.29 中 mac)路径必须是绝对路径。奇怪的是,对于 运行 迁移,相对路径将起作用,但应用程序在之后尝试访问数据库时失败
我正在 Laracasts 中从头开始学习系列 Laravel 5,具体来说,我正在上课 "Fetching Data"。
我创建了 database.sqlite 文件,我从 tinker 添加了一些数据,并能够在控制台中检索它们。然后,我尝试复制视频的内容。
我的卡片控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
class CardsController extends Controller
{
public function index()
{
$cards = \DB::table('cards')->get();
return view('cards.index', compact('cards'));
}
}
但是,当我尝试加载 /cards 路由时出现以下错误
InvalidArgumentException in SQLiteConnector.php line 34:
Database (homestead) does not exist.
这是我的 env
文件
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:P3ZgRMRkb2e8+x7S9rDLLB+bKJdR5Unpj8zXBUIHIZE=
APP_URL=http://localhost
DB_CONNECTION=sqlite
DB_FILE=database.sqlite
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
在您的错误中引用的那一行下面是:
// Here we'll verify that the SQLite database exists before going any further
// as the developer probably wants to know if the database exists and this
// SQLite driver will not throw any exception if it does not by default.
if ($path === false) {
throw new InvalidArgumentException("Database (${config['database']}) does not exist.");
}
看方法上面的注释,好像你的路径设置不正确。我相信正确的环境变量应该是:
DB_DATABASE=database/database.sqlite
而不是
DB_FILE=database/database.sqlite
如果没有,请检查您的 config/database.php
文件,并查找以下部分:
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')), // this line!
'prefix' => '',
],
我刚刚也注意到(至少在 Laravel 版本 5.2.29 中 mac)路径必须是绝对路径。奇怪的是,对于 运行 迁移,相对路径将起作用,但应用程序在之后尝试访问数据库时失败