Как правильно удалять все таблицы в laravel? - php artisan migrate:reset

При попытке удалить все таблицы мне пишет ошибку: ограничение внешнего ключа не выполнено.

> php artisan migrate:reset  

   INFO  Rolling back migrations.

  2024_09_20_124346_create_images_table ............................................................................................... 51.67ms DONE
  2024_09_18_133116_create_cart_table ................................................................................................. 77.57ms DONE
  2024_09_18_130751_create_prodcat_table ............................................................................................... 0.74ms DONE
  2024_09_18_130147_create_products_table ............................................................................................. 45.51ms FAIL

   Illuminate\Database\QueryException 

  SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails (Connection: mysql, SQL: drop table if exists `products`)

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:825
    821▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    822▕                 );
    823▕             }
    824▕
  ➜ 825▕             throw new QueryException(
    826▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    827▕             );
    828▕         }
    829▕     }

  1   vendor\laravel\framework\src\Illuminate\Database\Connection.php:571
      PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails")

  2   vendor\laravel\framework\src\Illuminate\Database\Connection.php:571
      PDOStatement::execute()

--- 2024_09_18_130751_create_prodcat_table ---

    public function up(): void
    {
        Schema::create('prodcats', function (Blueprint $table) {
            $table->id();

            $table->foreignId('product_id')->constrained()->onDelete('cascade');
            $table->foreignId('category_id')->constrained()->onDelete('cascade');

            $table->timestamps();
        });
    }

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

--- 2024_09_18_130147_create_products_table ---

    public function up(): void
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->integer('price');
            $table->string('name');
            $table->text('description');

            $table->foreignId('manufacturer_id')->constrained()->onDelete('cascade');
            $table->timestamps();
        });
    }

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

--- 2024_09_18_124929_create_manufacturers_table ---

    public function up(): void
    {
        Schema::create('manufacturers', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }

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

--- DatabaseSeeder ---

    public function run(): void
    {
        Manufacturer::factory(10)->create();

        Category::factory(10)->create();

        User::factory(10)->create();

        Product::factory(10)->create();

        Order::factory(10)->create();

        Prodcat::factory(10)->create();

        Cart::factory(10)->create();

        Image::factory(10)->create();
    }
});

Что мне нужно сделать, чтоб не удалять каждую таблицу отдельно?


Ответы (0 шт):