Can't seed the database in Laravel

前端 未结 2 1233
陌清茗
陌清茗 2021-01-29 11:10

I\'m currently seed my database in Laravel, migrations works properly and I am able to see the tables in SQL workbench. But when I run the command php artisan db:seed

相关标签:
2条回答
  • 2021-01-29 11:33

    You can also specify which seeder file to run by command php artisan db:seed --class=yourseedername Also in you seeder code you are inserting same data twice one by DB query and another from Book model. So you are duplicating same data twice. I believe an error should be thrown as column violation saying integrity constraint violation as isbn for books are unique.

    0 讨论(0)
  • 2021-01-29 11:38

    Within the DatabaseSeeder class, you may use the call method to execute additional seed classes. Using the call method allows you to break up your database seeding into multiple files so that no single seeder class becomes overwhelmingly large. Pass the name of the seeder class you wish to run:

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call([
            UserSeeder::class,
            PostSeeder::class,
            CommentSeeder::class,
        ]);
    }
    
    0 讨论(0)
提交回复
热议问题