【问题标题】:Laravel 9 seeder doesn't execute all seedersLaravel 9 播种机不执行所有播种机
【发布时间】:2022-11-27 00:57:55
【问题描述】:
我在 laravel 9 中遇到播种机问题。问题是当我想使用 php artisan db:seed、php artisan db:fresh 和应该执行所有播种机的类似命令来执行所有播种机时。仅当我使用 php artisan db:seed --class=UserSeeder 之类的命令和执行特定播种机的类似命令指定确切的类时,播种机才有效。我该如何解决这个问题并执行所有播种机?
【问题讨论】:
标签:
php
laravel
laravel-9
laravel-seeding
【解决方案1】:
php artisan db:seed命令的--class标志默认为DatabaseSeedersDatabaseSeeder,您可以通过发出php artisan db:seed --help来查看:
Description:
Seed the database with records
Usage:
db:seed [options] [--] [<class>]
Arguments:
class The class name of the root seeder
Options:
--class[=CLASS] The class name of the root seeder [default: "DatabaseSeedersDatabaseSeeder"]
--database[=DATABASE] The database connection to seed
--force Force the operation to run when in production
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
如果你想运行其他播种机而不必通过--class手动指定类,你可以do so within DatabaseSeeder via $this->call(...)。