【问题标题】:Laravel 5.4 Seeds not seeding all tablesLaravel 5.4 种子没有播种所有表
【发布时间】:2017-09-09 12:00:06
【问题描述】:

我在 Laravel 5.4 中播种,但它只播种一张桌子,其他桌子没有播种。 播种机是使用以下命令创建的:

php artisan make:seeder seederName

【问题讨论】:

    标签: php laravel laravel-seeding


    【解决方案1】:

    您应该在DatabaseSeeder.php 中注册所有播种机:

    $this->call(UsersTableSeeder::class);
    $this->call(PostsTableSeeder::class);
    $this->call(CommentsTableSeeder::class);
    

    在 DatabaseSeeder 类中,您可以使用 call 方法来执行额外的种子类。使用 call 方法可以将数据库播种分解为多个文件,这样单个播种器类就不会变得非常大。

    https://laravel.com/docs/5.4/seeding#calling-additional-seeders

    【讨论】:

      猜你喜欢
      • 2014-06-04
      • 2022-11-27
      • 2017-09-11
      • 2017-12-08
      • 2017-09-19
      • 2017-08-21
      • 2018-01-30
      • 2020-10-08
      • 2014-09-05
      相关资源
      最近更新 更多