没有数据库连接的 Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/57907842/
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
Laravel without database connection
提问by user2496520
is there a way to use Laravel without database connection? I am planning to create a frontend website using blade and VueJS that will consume third-party API and I don't need a database.
有没有办法在没有数据库连接的情况下使用 Laravel?我打算使用刀片和 VueJS 创建一个前端网站,该网站将使用第三方 API,而且我不需要数据库。
Currently, I am getting this error and I am not sure how to bypass it.
目前,我收到此错误,但不确定如何绕过它。
Database name seems incorrect
You're using the default database name laravel. This database does not exist.
Edit the .env file and use the correct database name in the DB_DATABASE key
回答by Prahlad Makwana
if you using internal artisan service for development server, you need to restart service:
如果您使用内部 artisan 服务作为开发服务器,则需要重新启动服务:
Ctrl + c
Ctrl + c
then run
然后运行
php artisan serve
php artisan serve
回答by bishop
This check appeared in Laravel 5.6.29, through the Ignition service's DefaultDbNameSolutionProvider
.
这个检查出现在 Laravel 5.6.29 中,通过 Ignition 服务的DefaultDbNameSolutionProvider
.
The solution message is a bit misleading, since it presumes you want to use a database. It's trying to convey that (a) you're configured to use a default database?, and (b) that default database does not exist, so (c) you should change the database name to the actual value for your environment.
解决方案消息有点误导,因为它假定您要使用数据库。它试图传达 (a) 您已配置为使用默认数据库?,以及 (b) 该默认数据库不存在,因此 (c) 您应该将数据库名称更改为您的环境的实际值。
Since you don't have a database, set DB_DATABASE=unused
and you should not get this error any more. Of course, if you call DB::connection()
, that will blow up. But that's expected.
由于您没有数据库,因此设置后DB_DATABASE=unused
您不应再收到此错误。当然,如果你调用DB::connection()
,那会爆炸。但这是意料之中的。
?The two database names Laravel recognizes as default are "laravel"
and "homestead"
.
? Laravel 默认识别的两个数据库名称是"laravel"
和"homestead"
。
回答by Tajni
Every change you make to the .env
file you need to restart your server.
您对.env
文件所做的每一次更改都需要重新启动服务器。
So you need to stop service by Ctrl + C
, killing process if you run in detached state or stop your Docker etc. Then run again with php artisan serve
or rerun your Docker container.
因此Ctrl + C
,如果您在分离状态下运行或停止 Docker 等,您需要停止服务,终止进程。然后再次运行php artisan serve
或重新运行您的 Docker 容器。
回答by Thalinda Bandara
I know this is a bit late but if someone needs this when you update your .env file you must restart your server to effect those new setting so close current running server C+ctrl
then again run PHP artisan serv
我知道这有点晚了,但是如果有人在更新 .env 文件时需要这个,则必须重新启动服务器以影响这些新设置,因此关闭当前正在运行的服务器C+ctrl
然后再次运行PHP artisan serv
回答by Liel van der Hoeven
If you are using Homestead as your development environment, you should change DB_DATABASE
from laravel
to homestead
, DB_USERNAME
to homestead
and DB_PASSWORD
to secret
.
如果你使用 Homestead 作为你的开发环境,你应该DB_DATABASE
从laravel
到homestead
,DB_USERNAME
到homestead
和DB_PASSWORD
到secret
。
A homestead database is configured for both MySQL and PostgreSQL out of the box. To connect to your MySQL or PostgreSQL database from your host machine's database client, you should connect to 127.0.0.1 and port 33060 (MySQL) or 54320 (PostgreSQL). The username and password for both databases is homestead / secret.
为 MySQL 和 PostgreSQL 配置了一个开箱即用的 homestead 数据库。要从主机的数据库客户端连接到 MySQL 或 PostgreSQL 数据库,您应该连接到 127.0.0.1 和端口 33060 (MySQL) 或 54320 (PostgreSQL)。两个数据库的用户名和密码都是 homestead / secret。
https://laravel.com/docs/7.x/homestead#connecting-to-databases
https://laravel.com/docs/7.x/homestead#connecting-to-databases