Таблица sites
:
id|name |
--|-----------------|
1|https://test.ru/ |
2|https://loop.com/|
Таблица counterparties
:
id|client_id|
1| 1 |
2| 1 |
Pivot-таблица
сounterparty_sites
:
id|counterparty_id|site_id|
--|---------------|-------|
1| 1 | 1 |
Миграция pivot-таблицы
:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCounterpartySite extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('counterparty_site', function(Blueprint $table) {
$table->id();
$table->foreignId('counterparty_id')->constrained()->onDelete('cascade');
$table->foreignId('site_id')->constrained()->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('counterparty_sites');
}
}
При попытке удалить таблицу как с данными так и бе них приводит к ошибке:
SQLSTATE[2BP01]: Dependent objects still exist: 7 ERROR: cannot drop table sites because other objects depend on it DETAIL: constraint counterparty_site_site_id_foreign on table counterparty_site depends on table sites HINT: Use DROP ... CASCADE to drop the dependent objects too. (SQL: drop table if exists "sites")
Я так понимаю, что не срабатывает каскад потому, что это не удаление записей, а удаление таблицы(sites
). Есть ли способ решить эту проблему, так чтобы сработал какскад?