Laravel 5 为什么回滚提升不能删除索引错误?

Laravel 5 为什么回滚提升不能删除索引错误?,laravel-5,migration,Laravel 5,Migration,在我的Laravel5.7应用程序中,我需要将其他表中的表和引用添加到创建的表中。 我制作了2个迁移文件和 migrate命令运行正常 但是运行回滚时我有一个错误: $ php artisan migrate Migrating: 2020_03_08_162307_create_colors_table Migrated: 2020_03_08_162307_create_colors_table Migrating: 2020_03_08_162642_add_color_storage_

在我的Laravel5.7应用程序中,我需要将其他表中的表和引用添加到创建的表中。 我制作了2个迁移文件和 migrate命令运行正常

但是运行回滚时我有一个错误:

$ php artisan migrate
Migrating: 2020_03_08_162307_create_colors_table
Migrated:  2020_03_08_162307_create_colors_table
Migrating: 2020_03_08_162642_add_color_storage_spaces_table
Migrated:  2020_03_08_162642_add_color_storage_spaces_table
serge@athoe:/mnt/_work_sdb8/wwwroot/lar/BoxBooking2$ php artisan migrate:rollback
Rolling back: 2020_03_08_162642_add_color_storage_spaces_table

   Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1553 Cannot drop index 'storage_spaces_color_id_foreign': needed in a foreign key constraint (SQL: alter table `storage_spaces` drop index `storage_spaces_color_id_foreign`)

  at /mnt/_work_sdb8/wwwroot/lar/BoxBooking2/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000]: General error: 1553 Cannot drop index 'storage_spaces_color_id_foreign': needed in a foreign key constraint")
      /mnt/_work_sdb8/wwwroot/lar/BoxBooking2/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:119

  2   PDOException::("SQLSTATE[HY000]: General error: 1553 Cannot drop index 'storage_spaces_color_id_foreign': needed in a foreign key constraint")
      /mnt/_work_sdb8/wwwroot/lar/BoxBooking2/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117

  Please use the argument -v to see more details.
这些文件是: 2020_03_08_162307_创建_颜色_table.php:

 <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateColorsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('colors', function (Blueprint $table) {
            $table->smallIncrements('id');
            $table->string('color', 10)->unique();
            $table->string('title', 50)->unique();
            $table->enum('status', [ 'BU', 'UDL', 'UBPNCI', 'R'     , 'NPC'  , 'AUWN' , 'A'  ])->nullable()->comment(', BU=>Booked Units / Client Checked-In already, UDL=>Units Double Locked, UBPNCI - Unit Booked/Paid, not check-in, R - Reserved, AUWN - Available Units with notes (For repair, with water leakage, under maintenance & etch...), NPC - Non Paying Clients,    A=>Available');

            $table->timestamp( 'created_at')->useCurrent();
        });
        Artisan::call('db:seed', array('--class' => 'AdColorsWithInitData'));
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('colors');
    }
}
您的错误是:

无法删除索引“存储空间颜色id外部”

索引名称应在dropForeign函数中匹配

试试看,希望能奏效

Schema::table('storage_spaces', function (Blueprint $table) {
      $table->dropForeign('storage_spaces_color_id_foreign);
      $table->dropColumn('color_id');
 });
您的错误是:

无法删除索引“存储空间颜色id外部”

索引名称应在dropForeign函数中匹配

试试看,希望能奏效

Schema::table('storage_spaces', function (Blueprint $table) {
      $table->dropForeign('storage_spaces_color_id_foreign);
      $table->dropColumn('color_id');
 });