## 1.确认database.php文件配置正确。
首先检查database.php中自己填写的信息是正确的。
## 2.检查.env文件
这是默认的.env文件
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
取对应的数据库部分
我用的是mysql数据库
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
## 3.修改.env文件
将上述的部分做如下修改
DB_CONNECTION=mysql
DB_HOST=[你的数据库地址]
DB_PORT=[端口(3306)]
DB_DATABASE=[数据库]
DB_USERNAME=[用户名]
DB_PASSWORD=[密码]
## 4.重启服务
php artisan cache:clear
php artisan config:clear
php artisan serve
cd app/Providers
vim AppServiceProvider.php:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
[root@localhost xiaohu]# php artisan migrate
Migrating: 2017_12_24_114108_create_table_users
Migrated: 2017_12_24_114108_create_table_users
[root@localhost xiaohu]# php artisan migrate:rollback
Rolling back: 2017_12_24_114108_create_table_users
Rolled back: 2017_12_24_114108_create_table_users
[root@localhost xiaohu]# php artisan migrate
Migrating: 2017_12_24_114108_create_table_users
Migrated: 2017_12_24_114108_create_table_users