数据库(database/database.sqlite)不存在.工匠修补匠的数据库作品 [英] Database (database/database.sqlite) does not exist. Database works from artisan tinker

查看:215
本文介绍了数据库(database/database.sqlite)不存在.工匠修补匠的数据库作品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在database文件夹中创建了database.sqlite文件.我的.env文件内容是:

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=

当我运行php artisan tinkerDB::table('users')->get();时,我从数据库中获取信息.

When I run php artisan tinker and DB::table('users')->get(); I get the info from the database.

我的DatabaseController是:

My DatabaseController is:

class DatabaseController extends Controller
{
    public function main()
    {
        $users = DB::table('users')->get();

        return view('database',compact($users));
    }
}

但是当我请求/database路径时,我得到了错误:

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")

QueryException in Connection.php line 647: Database (database/database.sqlite) does not exist. (SQL: select * from "users")

更新: 暂时的解决方法是从config文件夹中更改database.php:

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' => '',
    ],

代替使用env('DB_DATABASE', database_path('database.sqlite')),它返回database/database.sqlite而不是我的绝对路径.

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

这篇关于数据库(database/database.sqlite)不存在.工匠修补匠的数据库作品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆