diff --git a/timeliner/database/migrations/2024_10_09_194444_create_nodes_table.php b/timeliner/database/migrations/2024_10_09_194444_create_nodes_table.php index 6b174bf..8cda6bd 100644 --- a/timeliner/database/migrations/2024_10_09_194444_create_nodes_table.php +++ b/timeliner/database/migrations/2024_10_09_194444_create_nodes_table.php @@ -15,7 +15,7 @@ public function up(): void $table->id('id'); $table->string('name'); $table->string('color'); - $table->integer('timeline'); + $table->unsignedBigInteger('timeline'); $table->foreign('timeline')->references('id')->on('timelines')->onDelete('cascade'); diff --git a/timeliner/database/migrations/2024_10_09_194452_create_milestones_table.php b/timeliner/database/migrations/2024_10_09_194452_create_milestones_table.php index 17b8374..a8267b7 100644 --- a/timeliner/database/migrations/2024_10_09_194452_create_milestones_table.php +++ b/timeliner/database/migrations/2024_10_09_194452_create_milestones_table.php @@ -15,7 +15,7 @@ public function up(): void $table->id(); $table->string('description'); $table->date('date'); - $table->integer('node'); + $table->unsignedBigInteger('node'); $table->foreign('node')->references('id')->on('nodes')->onDelete('cascade'); diff --git a/timeliner/database/seeders/MilestoneSeeder.php b/timeliner/database/seeders/MilestoneSeeder.php index 85f80ac..7694d00 100644 --- a/timeliner/database/seeders/MilestoneSeeder.php +++ b/timeliner/database/seeders/MilestoneSeeder.php @@ -26,11 +26,7 @@ public function run(): void ]; foreach ($milestones as $milestone) { - Milestone::create(array( - 'description' => $milestone['description'], - 'date' => $milestone['date'], - 'node' => $milestone['node'] - )); + Milestone::create($milestone); } } } diff --git a/timeliner/database/seeders/NodeSeeder.php b/timeliner/database/seeders/NodeSeeder.php index 833cd44..d89265a 100644 --- a/timeliner/database/seeders/NodeSeeder.php +++ b/timeliner/database/seeders/NodeSeeder.php @@ -6,6 +6,7 @@ use App\Models\Node; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\DB; class NodeSeeder extends Seeder { @@ -14,7 +15,9 @@ class NodeSeeder extends Seeder */ public function run(): void { + DB::statement('SET FOREIGN_KEY_CHECKS=0;'); Node::truncate(); + DB::statement('SET FOREIGN_KEY_CHECKS=1;'); $nodes = [ ['name' => "Jules' concerts", 'color' => '#ffc0cb', 'timeline' => "1"], @@ -24,11 +27,7 @@ public function run(): void ]; foreach ($nodes as $node) { - Node::create(array( - 'name' => $node['name'], - 'color' => $node['color'], - 'timeline' => $node['timeline'] - )); + Node::create($node); } } } diff --git a/timeliner/database/seeders/TimelineSeeder.php b/timeliner/database/seeders/TimelineSeeder.php index 6e2e49a..b9c5465 100644 --- a/timeliner/database/seeders/TimelineSeeder.php +++ b/timeliner/database/seeders/TimelineSeeder.php @@ -5,6 +5,7 @@ use App\Models\Timeline; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\DB; class TimelineSeeder extends Seeder { @@ -12,8 +13,10 @@ class TimelineSeeder extends Seeder * Run the database seeds. */ public function run(): void - { + { + DB::statement('SET FOREIGN_KEY_CHECKS=0;'); Timeline::truncate(); + DB::statement('SET FOREIGN_KEY_CHECKS=1;'); $timelines = [ ['name' => "Timeline number one", 'private' => false, 'description' => "an important timeline"], @@ -21,11 +24,7 @@ public function run(): void ]; foreach ($timelines as $timeline) { - Timeline::create(array( - 'name' => $timeline['name'], - 'private' => $timeline['private'], - 'description' => $timeline['description'] - )); + Timeline::create($timeline); } } }