'how can I solve laravel php artisan migrate error problem?
I'm using laravel socialite to make facebook login, following this website: 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')
Solution 1:[1]
Open the .env file and edit it. Just set up correct DB credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username
DB_PASSWORD= // Your Database Password
The DB_USERNAME should be set to root if you do not have a default username
If no password is set on the database, clear it DB_PASSWORD
After completion of .env edit must be clear cache: php artisan config:cache
After Run the migrate Artisan command: php artisan migrate
Solution 2:[2]
The database called laravel cannot be found in PhpMyAdmin
Please follow these steps to solve this problem :
Go to
phpmyadminin your localhost dashboardCreate a database and name it
laravelrun the
php artisan migrateCMD or Terminal of your editor
Solution 3:[3]
I had the same issue But changing localhost with 127.0.0.1 solved it for me
DB_CONNECTION=mysql
DB_PORT=3306
DB_HOST=127.0.0.1
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
Solution 4:[4]
Question is not about facebook login. You migration command could not establish connection with your database actually.
Check you .env file, you need to have something like this
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.
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)
Solution 5:[5]
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.
Solution 6:[6]
At first stance this points to a problem in the .env and ./config/database.php files. In the .env file you should have something like this
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
and in ./config/database.php something like this
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DATABASE_HOST','localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DATABASE_NAME','laravel'),
'username' => env('DATABASE_USERNAME','root'),
'password' => env('DATABASE_PASSWORD',''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
If your console were showing you something like this
Database hosts array is empty. (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
you had to ensure to have specified the host. This would've happen if you had in ./config/database.php something like this (notice that it doesn't refer 'localhost' like before)
'host' => env('DATABASE_HOST'),
Assuming all is fine here and you have the database name you want to use, then it means that your database doesn't exist. Just go to phpmyadmin, or so, and create one.
Solution 7:[7]
The issue for me was the database.php config file did not have the PORT config, so it was default to 3306, but my database used a different port. I just added the line of config to the mysql config:
'mysql' => [
'port' => env('DB_PORT', '3306')
]
Solution 8:[8]
Solution founded. I had the same problem. the reason for the problem is there is no any database called "laravel" in phpmyadmin. It may be deleted or renamed. So check whether there is a database called 'laravel'. If it's not present create database in phpmyadmin using the name,
laravel
After that run the command,
php artisan migrate
This worked for me
Solution 9:[9]
As you can see from the answers above that you need the change the name of the database in the .env file , make sure you are changing on the .env instead of .env.example file
Solution 10:[10]
php artisan route:cache
apply this command and solved my error
Solution 11:[11]
i solved the problem by writing the database name in single quotes...
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE='laravel'
DB_USERNAME=root
DB_PASSWORD=
Solution 12:[12]
I had the same issue But changing DB_HOST=127.0.0.1 to DB_HOST:localhost solved it for me
DB_HOST=localhost //DB_HOST=127.0.0.1 to DB_HOST:localhost solved
DB_PORT=3306
DB_DATABASE=laravel_multiauth
DB_USERNAME=root
DB_PASSWORD=
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
