Here are some additional useful migration commands and their usage in short:

1. Creating a Migration for a Specific Table

To create a migration for modifying an existing table:

php artisan make:migration modify_users_table --table=users
  • This creates a migration for the users table where you can add or remove columns.

2. Running All Pending Migrations

To run all pending migrations (i.e., applying changes to the database):

php artisan migrate
  • This applies all migrations that have not been run yet.

3. Rolling Back the Last Migration Batch

To rollback the last batch of migrations:

php artisan migrate:rollback
  • It will run the down() method of the last set of migrations.

4. Rolling Back All Migrations

To rollback all migrations, effectively reverting the database to its original state:

bashCopyphp artisan migrate:reset
  • This reverts all migrations by running the down() method in each migration.

5. Refreshing the Database

To reset and then re-run all migrations (useful for development when you want a fresh database):

php artisan migrate:refresh
  • This will rollback all migrations and then run them again from the beginning.

6. Refreshing Migrations with Seed Data

To refresh the database and also run the seeder to populate the tables with sample data:

php artisan migrate:refresh --seed
  • This will rollback, re-run the migrations, and populate your database with default data defined in your seeders.

7. Viewing the Status of Migrations

To see the status of all migrations (whether they’ve been run or not):

php artisan migrate:status
  • This lists all migrations and shows their current state (Yes or No).

8. Rolling Back a Specific Number of Migrations

To rollback a specific number of migrations (e.g., last 3):

php artisan migrate:rollback --step=3
  • This will rollback 3 migrations instead of just one.

9. Force Migrations in Production

If you are working in a production environment, use the --force option to run migrations:

php artisan migrate --force
  • This is necessary because Laravel prevents running migrations in production by default to prevent accidental data loss.

10. Creating a Migration with Custom Column Types

To create custom columns like boolean, enum, timestamps, etc., you can use commands like:


$table->boolean('is_active');
$table->enum('status', ['draft', 'published', 'archived']);
$table->timestamps();

These are some common and advanced migration commands that help manage your database schema in Laravel. Each one can be used in different situations depending on your project’s needs!