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
.
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
.
use Undo Seeder for Laravel.
When you install UndoSeeder, the following artisan commands are made available:
db:seed-undo Undo seeds in the seeds directory.
db:seed-refresh Undo seeds run seeds again.
more Undo-Seeder
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:
php artisan migrate:refresh --seed
If you want to wipe out certain table, then just TRUNCATE that table, and seed it again:
php artisan db:seed --class=UsersTableSeeder
No need for additional packages for such a simple task.
The easiest method is to go into your
database/seeders
folder and manually delete the files you want to remove then run php artisan migrate:fresh
.
Open the database table with whichever platform you are using (phpMyAdmin / mySql-Workbench / a DB-editor plug-in etc.) and manually delete the seeded contents. Then you will be able to reseed the table using php artisan db:seed
I was looking for something else like i have ran php artisan db:seed
and after that I wanted to change something in UserSeeder
, like changing an email address.
So if you want to change something in Seeder class and you have already run db:seed
command.
Then first of all you have to add truncate function before any other code like if you have UserSeeder
class then add below code in run function before seeding all User
model:
User::truncate();
Then all you have to do is re-run the command.
php artisan db:seed
It will seed again all the classes as per your change and delete already seeded Users
in Database, You can use this method for any model you want to truncate the table and re insert the records.