【问题标题】:laravel migration syntax error or access violation "Duplicate key name alter table and add indexlaravel 迁移语法错误或访问冲突\"Duplicate key name alter table and add index
【发布时间】:2023-02-03 18:47:31
【问题描述】:

我正在开发一个给我的新代码库,它是用 laravel 编写的

我尝试运行迁移,但出现以下错误

SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'artisan_services_user_id_index' (SQL: alter table `artisan_services` add index `artisan_services_user_id_i
ndex`(`user_id`))

这是迁移代码。

 public function up()
    {
        Schema::create('artisan_services', function (Blueprint $table) {
            $table->id();
            $table->string('user_id',10)->nullable();
            $table->text('profile_picture')->nullable();
            $table->longText('title')->nullable();
            $table->longText('full_name')->nullable();
            $table->text('feature_image')->nullable();
            $table->text('business_category')->nullable();
            $table->string('phone',50)->nullable();
            $table->longText('email')->nullable();
            $table->longText('website')->nullable();
            $table->text('cost')->nullable();
            $table->longText('per_service')->nullable();
            $table->longText('street_address')->nullable();
            $table->longText('city')->nullable();
            $table->longText('state')->nullable();
            $table->longText('service_description')->nullable();
            $table->longText('experience')->nullable();
            $table->string('status',10)->default(0)->nullable();
            $table->longText('rating')->nullable();
            $table->longText('review')->nullable();
            $table->longText('employers')->nullable();
            $table->timestamps();

        });
    }

   
    public function down()
    {
        Schema::dropIfExists('artisan_services');
    }

【问题讨论】:

    标签: php laravel migration syntax-error


    【解决方案1】:

    说您已经以某种方式创建了该索引。您需要在创建之前删除该索引。将这段代码置顶

     $table->dropIndex('artisan_services_user_id_index');
    

    【讨论】:

      猜你喜欢
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 2019-10-15
      • 2023-02-10
      • 2018-02-06
      • 2016-04-26
      • 2019-02-10
      • 2014-03-17
      相关资源
      最近更新 更多