Skip to content

Commit 134c9e3

Browse files
committed
update(seed): 清除表时先忽略外键约束
1 parent 9956ee5 commit 134c9e3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

laravel/database/seeds/DatabaseSeeder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class DatabaseSeeder extends Seeder
1111
*/
1212
public function run()
1313
{
14+
// 清除表时先忽略外键约束
15+
$this->foreign(0);
1416
$this->call(UsersTableSeeder::class);
1517
$this->call(CronTasksTableSeeder::class);
1618
$this->call(LinesTableSeeder::class);
@@ -20,5 +22,11 @@ public function run()
2022
$this->call(RolesTableSeeder::class);
2123
$this->call(PermissionRoleTableSeeder::class);
2224
$this->call(RoleUserTableSeeder::class);
25+
$this->foreign(1);
26+
}
27+
28+
public function foreign($type = 0)
29+
{
30+
DB::statement("SET FOREIGN_KEY_CHECKS=$type");
2331
}
2432
}

0 commit comments

Comments
 (0)