HomeLARAVELDifference between php artisan migrate and php artisan migrate:fresh.

Difference between php artisan migrate and php artisan migrate:fresh.

In Laravel, both php artisan migrate and php artisan migrate:fresh are used for handling database migrations, but they serve different purposes and behave differently. Let’s break it down clearly:


1. php artisan migrate

  • Purpose: Applies new migrations that haven’t been run yet.
  • Behavior:
    • Looks at the migrations table in the database.
    • Runs only the migrations that are not yet executed.
    • Does not delete existing tables or data.
  • Use case: When you add a new migration (like creating a new table or modifying an existing one) and want to apply it without losing existing data.

Example:

php artisan migrate
  • If you already ran users table migration before, Laravel will skip it and only run migrations that are new.

2. php artisan migrate:fresh

  • Purpose: Drops all tables in the database and then runs all migrations from scratch.
  • Behavior:
    • Deletes all existing tables in the database.
    • Runs all migrations from the beginning.
    • Any existing data will be lost.
  • Use case: Useful during development when you want to reset the database completely and start fresh.
    Often used together with seeders:
php artisan migrate:fresh --seed

This will reset your database and populate it with seed data.


Summary Table

CommandDeletes Existing Tables?Runs Only New Migrations?Data LossUse Case
php artisan migrate❌ No✅ Yes❌ NoApply new migrations safely
php artisan migrate:fresh✅ Yes❌ No (runs all)✅ YesReset DB in development

💡 Tip: Never use migrate:fresh in production as it wipes all data. It’s meant only for local/dev environments.

Share: 

No comments yet! You be the first to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *