作者:陈业贵 华为云享专家 51cto(专家博主 明日之星 TOP红人) 阿里云专家博主
报错信息:
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException
SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘users’ already exists (SQL: create table users
(id
bigint unsigned not null auto_increment primary key, name
varchar(191) not null, email
varchar(191) not null, email_verified_at
timestamp null, password
varchar(191) not null, remember_token
varchar(100) null, created_at
timestamp null, updated_at
timestamp null) default character set utf8mb4 collate ‘utf8mb4_unicode_ci’)
at D:\phpstudy_pro\WWW\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we’ll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database’s errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query,
t
h
i
s
−
>
p
r
e
p
a
r
e
B
i
n
d
i
n
g
s
(
this->prepareBindings(
this−>prepareBindings(bindings), $e
714▕ );
715▕ }
716▕ }
1 D:\phpstudy_pro\WWW\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:501
PDOException:😦“SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘users’ already exists”)
2 D:\phpstudy_pro\WWW\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:501
PDOStatement::execute()
解决方案:
use Illuminate\Support\Facades\Schema;
Schema::defaultStringLength(191);这句加在boot函数里面
把boot函数放到最上面
<?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()
{
//
}
}