播种到数据库后,laravel 种子回滚

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44729769/
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-14 16:12:03  来源:igfitidea点击:

laravel seed rollback after seeded to database

laravelrollbacklaravel-seeding

提问by Aaron

I have seeded my db using php artisan db::seed. Is there a way to rollback what I have seeded into my db. I cannot seem to find any command like php artisan db::seed rollback

我已经使用php artisan db::seed. 有没有办法回滚我在数据库中播种的内容。我似乎找不到任何命令php artisan db::seed rollback

回答by Leo

use Undo Seeder for Laravel.

为 Laravel 使用 Undo Seeder。

When you install UndoSeeder, the following artisan commands are made available:

安装 UndoSeeder 时,以下工匠命令可用:

db:seed-undo    Undo seeds in the seeds directory.
db:seed-refresh Undo seeds run seeds again.

more Undo-Seeder

更多Undo-Seeder

回答by V-E-Y

You may also seed your database using the migrate:refresh command, which will also rollback and re-run all of your migrations. This command is useful for completely re-building your database:

您还可以使用 migrate:refresh 命令为您的数据库设定种子,该命令还将回滚并重新运行您的所有迁移。此命令对于完全重建数据库很有用:

php artisan migrate:refresh --seed

php artisan migrate:refresh --seed

Running Seeders

运行播种机

回答by Alexander Kim

If you want to wipe out certain table, then just TRUNCATE that table, and seed it again:

如果你想清除某个表,那么只需 TRUNCATE 该表,然后再次播种:

php artisan db:seed --class=UsersTableSeeder

No need for additional packages for such a simple task.

如此简单的任务不需要额外的包。

回答by Haritsinh Gohil

I was looking for something else like i have run php artisan db:seedand after that i wanted to change something in UserSeeder, like changing an email address.

我一直在寻找其他类似我已经运行过的东西php artisan db:seed,之后我想更改 . 中的某些内容UserSeeder,例如更改电子邮件地址。

So if you want to change something in Seeder class and you have already run db:seedcommand

因此,如果您想更改 Seeder 类中的某些内容并且您已经运行db:seed命令

Then all you have to do is change Your Seeder class functionality as per your choice then re-run the command

然后您所要做的就是根据您的选择更改您的 Seeder 类功能,然后重新运行命令

php artisan db:seed 

it will seed again All the classes as per your change.

它将根据您的更改再次播种所有课程。