laravel8.x 报错信息: Illuminate\Database\QueryException SQLSTATE[42S01]: Base table or view already

作者:陈业贵 华为云享专家 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()
    {
        //
    }


}

效果:(已经解决)

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贵哥的编程之路(热爱分享)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值