laravel 数据库 (database/database.sqlite) 不存在。来自工匠修补匠的数据库作品

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43140711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:41:44  来源:igfitidea点击:

Database (database/database.sqlite) does not exist. Database works from artisan tinker

databaselaravelsqliteconfigurationconnection

提问by Alexandru Antochi

I created my database.sqlite file in the databasefolder. My .envfile contents are :

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

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 tinkerand DB::table('users')->get();I get the info from the database.

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

My DatabaseController is:

我的数据库控制器是:

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

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

Yet when I request /databasepath I get the error:

然而,当我请求/database路径时,我收到错误消息:

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

UPDATE: A temporary fix is to change the database.php from the configfolder:

更新:临时修复是更改config文件夹中的 database.php :

  '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.sqlitenot my absolute path.

而不是 using env('DB_DATABASE', database_path('database.sqlite')),它返回的database/database.sqlite不是我的绝对路径。

回答by Alexey Mezenin

You need to use full path, something like:

您需要使用完整路径,例如:

DB_DATABASE=/home/laravel-project/database/database.sqlite

回答by gdfgdfg

If you remove DB_DATABASE=...from your .envfile and use the path in the config/database.php:

如果您DB_DATABASE=....env文件中删除并使用以下路径config/database.php

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

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

(if your database.sqlitefile is in database/folder), it will work, too.

(如果您的database.sqlite文件在database/文件夹中),它也可以工作。

回答by Alexandru Antochi

I ran the following commands:

我运行了以下命令:

php artisan config:cache

php artisan config:cache

php artisan config:clear

php artisan config:clear

php artisan serve- restarted the server

php artisan serve- 重新启动服务器

回答by Rodrigo

For those who still face this issue: https://laracasts.com/discuss/channels/general-discussion/database-databasedatabasesqlite-does-not-exist-error-on-running?page=1

对于那些仍然面临这个问题的人: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:

由于 sqlite 只需要 .env 文件中的 DB_CONNECTION=sqlite ,因此您只需删除另一个:

DB_HOST
DB_PORT
DB_DATABASE
DB_USERNAME
DB_PASSWORD

then save and run migration again. This was how I solved the problem. Cheers!

然后再次保存并运行迁移。这就是我解决问题的方法。干杯!

回答by Sarwar Sikder

In config/database.php file:

在 config/database.php 文件中:

'sqlite' => [
              'driver' => 'sqlite',
              'database' => dirname(__DIR__).'/database/database.sqlite',
            ],

Then run following command:

然后运行以下命令:

php artisan config:cache
php artisan config:clear

回答by Sergio Tskhovrebov

I think, that the problem here was because of Homestead. Absolute path to the database.sqlitefile on local machine is not the same as the virtual machine one has.

我认为,这里的问题是因为Homestead。本地机器上database.sqlite文件的绝对路径与虚拟机上的不同。

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=