Laravel从枢轴中删除id和时间戳

时间:2018-01-03 21:52:45

标签: laravel

我创建了一个数据透视表,并意外地为其添加了内容和时间戳。我有一些数据,所以宁愿使用迁移来修复它与反对回滚。

我尝试了这个但收到错误:

移植

Schema::table('hole_tee', function (Blueprint $table) {
            $table->dropPrimary('hole_tee_id_primary');
            $table->dropColumn('id');
            $table->dropTimestamps();   
            $table->primary(['hole_id', 'tee_id']);
});

错误:

SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as
  a key (SQL: alter table `hole_tee` drop primary key)


  SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as
  a key

创建表的原始迁移

Schema::create('holes', function (Blueprint $table) {
            $table->increments('id');

            $table->integer('scorecard_id');
            $table->integer('number');

            $table->timestamps();
        });

        Schema::create('hole_tee', function (Blueprint $table) {
            $table->increments('id');

            $table->integer('hole_id');
            $table->integer('tee_id');
            $table->integer('yardage');
            $table->integer('par');
            $table->integer('handicap');

            $table->timestamps();
        });

0 个答案:

没有答案