如何解决 Laravel php artisan 迁移错误问题?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/57770638/
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
how can I solve laravel php artisan migrate error problem?
提问by Johnny Jeong
I'm using laravel socialite to make facebook login, following this website: Social Logins with Socialite
我正在使用 laravel socialite 登录 facebook,关注这个网站:Social Logins with Socialite
as soon as I type a command in the terminal:
一旦我在终端中输入命令:
php artisan migrate
This shows the error:
这显示错误:
Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] 未知数据库“laravel”(SQL:从 information_schema.tables 中选择 * 其中 table_schema = laravel 和 table_name = 迁移和 table_type = 'BASE TABLE')
回答by Udhav Sarvaiya
Open the .env
file and edit it. Just set up correct DB credentials:
打开.env
文件并进行编辑。只需设置正确的数据库凭据:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Yout Database Username
DB_PASSWORD= // Your Database Password
The DB_USERNAME
should be set to rootif you do not have a default username
如果您没有默认用户名,DB_USERNAME
则应设置为root
If no passwordis set on the database, clear it DB_PASSWORD
如果数据库没有设置密码,清除它DB_PASSWORD
After completion of .env edit must be clear cache: php artisan config:cache
.env 编辑完成后必须清除缓存: php artisan config:cache
After Run the migrate Artisan command: php artisan migrate
运行 migrate Artisan 命令后: php artisan migrate
回答by Zadiki Hassan Ochola
I had the same issue But changing localhost with 127.0.0.1 solved it for me
我有同样的问题但是用 127.0.0.1 更改 localhost 为我解决了它
DB_CONNECTION=mysql
DB_PORT=3306
DB_HOST=127.0.0.1
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
回答by kwaku takyi
The database called laravel
cannot be found in PhpMyAdmin
laravel
无法在以下位置找到调用的数据库PhpMyAdmin
Please follow these steps to solve this problem :
请按照以下步骤解决此问题:
Go to
phpmyadmin
in your localhost dashboardCreate a database and name it
laravel
run the
php artisan migrate
CMD or Terminal of your editor
转到
phpmyadmin
您的本地主机仪表板创建数据库并命名
laravel
运行
php artisan migrate
编辑器的CMD 或终端
回答by lubart
Looks like you forgot to setup your Laravel application.
You can specify database connections and other basic settings in your .env
file in the root of your project.
看起来您忘记设置 Laravel 应用程序。您可以.env
在项目根目录的文件中指定数据库连接和其他基本设置。
回答by Rob Mkrtchyan
Question is not about facebook login. You migration command could not establish connection with your database actually.
问题与 Facebook 登录无关。您的迁移命令实际上无法与您的数据库建立连接。
Check you .env
file, you need to have something like this
检查你的.env
文件,你需要有这样的东西
DB_CONNECTION=mysql
DB_PORT=3306
DB_HOST=localhost
DB_DATABASE=laravel // This is line which you need to update, set here the real database name
DB_USERNAME=root
DB_PASSWORD=
If you have not file .env
you can rename .env.example
to .env
, setup you db configs, and you will be able to migrate your tables with migrate
command.
如果您没有文件,.env
您可以重命名.env.example
为.env
,设置您的数据库配置,您将能够使用migrate
命令迁移您的表。
If you want to call you db as laravel, it means you forgot to create that database, first create database using command line with mysql or any application which can work with mysql (phpMyAdmin, DataGrip, phpStorm, jetbrain Db, etc)
如果你想叫你 db 作为 laravel,这意味着你忘记创建那个数据库,首先使用命令行使用 mysql 或任何可以与 mysql 一起工作的应用程序(phpMyAdmin、DataGrip、phpStorm、jetbrain Db 等)创建数据库