Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed migration and seeding issues, resolved foreign key constraints #621

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions database/seeders/ArticlesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Seeders;

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Article;
Expand All @@ -11,6 +12,10 @@ class ArticlesTableSeeder extends Seeder
{
public function run()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Article::query()->delete();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

$users = User::all();
foreach ($this->articles as $article) {
Article::create([
Expand Down
4 changes: 3 additions & 1 deletion database/seeders/BlogSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class BlogSeeder extends Seeder
{
public function run(): void
{
DB::table('blogs')->truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Blog::query()->delete();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');

$categories = ['Business', 'Food', 'Lifestyle', 'World News'];
$images = [
Expand Down
6 changes: 5 additions & 1 deletion database/seeders/CategoriesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Seeder;
use App\Models\Category;
use Illuminate\Support\Facades\DB;

class CategoriesTableSeeder extends Seeder
{
Expand All @@ -15,7 +16,10 @@ class CategoriesTableSeeder extends Seeder
public function run()
{
// Truncate the table to remove existing records
Category::truncate();
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
Category::query()->delete();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');


// Define categories
$categories = [
Expand Down
Loading