fix: #58 - pivot table logo_site was broken, foreign keys were inverted
This commit is contained in:
parent
9065e3295a
commit
d1855d8771
1 changed files with 44 additions and 0 deletions
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// The foreign keys in the database were inverted, so i needed to recreate them and reinsert the datas.
|
||||
$relations = DB::table('logo_site')->get();
|
||||
Schema::dropIfExists('logo_site');
|
||||
Schema::create('logo_site', function (Blueprint $table) {
|
||||
$table->foreignId('logo_id')->constrained()->cascadeOnUpdate()->cascadeOnDelete();
|
||||
$table->foreignId('site_id')->constrained()->cascadeOnUpdate()->cascadeOnDelete();
|
||||
});
|
||||
|
||||
foreach ($relations as $relation) {
|
||||
DB::table('logo_site')->insert(
|
||||
[
|
||||
'logo_id' => $relation->logo_id,
|
||||
'site_id' => $relation->site_id,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('logo_site');
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue