laravel8.x 报错信息: IlluminateDatabaseQueryException SQLSTATE[42S01]: Base table or view already

2023-10-16 16:10:12 浏览数 (2)

报错信息:

Migrating: 2014_10_12_000000_create_users_table IlluminateDatabaseQueryException 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_proWWWblogvendorlaravelframeworksrcIlluminateDatabaseConnection.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),

解决方案:

代码语言:javascript复制
use IlluminateSupportFacadesSchema;
 Schema::defaultStringLength(191);这句加在boot函数里面
 把boot函数放到最上面
代码语言:javascript复制
<?php

namespace AppProviders;

use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
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 人点赞