Laravel Specific Table Migration & Seeder

Laravel Specific Table Migration & Seeder

Laravel Migration & Seeder Tips (Specific File/Class)

1. Run a Specific Migration File

php artisan migrate --path=/database/migrations/2024_01_01_000000_create_users_table.php

Tip:
Make sure the path starts from the base Laravel directory. Double-check the filename and timestamp.

2. Rollback a Specific Migration File

php artisan migrate:rollback --path=/database/migrations/2024_01_01_000000_create_users_table.php

Note:
This works only for files migrated in the last batch; otherwise, it will not affect anything.

3. Refresh a Specific Migration File

php artisan migrate:refresh --path=/database/migrations/2024_01_01_000000_create_users_table.php

This command:

  • Rolls back the specific migration

  • Then runs it again (refresh)

4. Run a Specific Seeder Class

php artisan db:seed --class=UsersTableSeeder

Make sure:

  • The seeder class exists in database/seeders/

  • The class name is correct and matches the filename

📝 Quick Summary Table

CommandPurpose
migrate --path=...Run one specific migration file
migrate:rollback --path=...Rollback one specific migration file
migrate:refresh --path=...Rollback & re-run one migration
db:seed --class=SeederClassRun a specific seeder class
Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close