Laravel Migration: Fresh vs Refresh

artisan migrate:fresh

php artisan migrate:fresh

This command:

  1. Drops all tables in the database
  2. Runs all migrations from scratch

Key points:

  • Completely wipes out the database
  • Faster than refresh for large numbers of migrations
  • Ideal for development/testing environments
  • Caution: All data will be lost

artisan migrate:rollback

php artisan migrate:refresh

This command:

  1. Rolls back all migrations
  2. Then runs all migrations again

Key points:

  • Preserves the database structure
  • Slower than fresh for many migrations
  • Useful when you want to keep some data integrity
  • Can be combined with --seed to repopulate data

When to use which?

  • Use fresh when:

    • You want a clean slate
    • You're in early development stages
    • You're setting up a new environment
  • Use refresh when:

    • You want to test incremental changes
    • You're working with a more stable database schema
    • You need to preserve some data relationships

Leave a Reply

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