如何解决 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

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

how can I solve laravel php artisan migrate error problem?

phpmysqllaravelmacos

提问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 .envfile 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_USERNAMEshould 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 laravelcannot be found in PhpMyAdmin

laravel无法在以下位置找到调用的数据库PhpMyAdmin

Please follow these steps to solve this problem :

请按照以下步骤解决此问题:

  1. Go to phpmyadminin your localhost dashboard

  2. Create a database and name it laravel

  3. run the php artisan migrateCMD or Terminal of your editor

  1. 转到phpmyadmin您的本地主机仪表板

  2. 创建数据库并命名 laravel

  3. 运行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 .envfile 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 .envfile, 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 .envyou can rename .env.exampleto .env, setup you db configs, and you will be able to migrate your tables with migratecommand.

如果您没有文件,.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 等)创建数据库