database Laravel 4 db 种子特定种子文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20039684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:07:47  来源:igfitidea点击:

Laravel 4 db seed specific seeder file

databaselaravel-4

提问by user1995781

I have an existing user table with information seeded via db:seedfrom UserSeeder.php. Now, I am adding new product table and want to seed information into product table. How can I prevent Laravel from seeding the UserSeeder into the database, but only the new ProductSeeder being seeded?

我有一个现有的用户表,其中包含通过db:seedUserSeeder.php播种的信息。现在,我正在添加新的产品表并希望将信息播种到产品表中。如何防止 Laravel 将 UserSeeder 播种到数据库中,但只播种新的 ProductSeeder?

Thanks.

谢谢。

回答by Sajan Parikh

You can call individual seed classes by their class name. From the docs.

您可以按类名调用单个种子类。从文档

By default, the db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes. However, you may use the --class option to specify a specific seeder class to run individually:

默认情况下,db:seed 命令运行 DatabaseSeeder 类,该类可用于调用其他种子类。但是,您可以使用 --class 选项指定要单独运行的特定播种机类:

php artisan db:seed --class=ProductTableSeeder

In the example above, the ProductTableSeederclass should exist in database/seeds.

在上面的例子中,ProductTableSeeder类应该存在于database/seeds.

回答by Mahmoud Zalt

Here's a working example with the class full namespace:

这是一个具有完整命名空间的类的工作示例:

Should use double backslashes \\.

应该使用双反斜杠\\

Class name is DefaultBannersSeeder.

班级名称是DefaultBannersSeeder.

php artisan db:seed --class=App\Containers\Banners\Data\Seeders\DefaultBannersSeeder