How to Run a Specific Migration File in Laravel

October 14th, 2024 • 1 minute read time

If you just need to run a single migration file in Laravel, here's how to do it.

Regardless of what your migration looks like, you're able to run individual migration files using artisan. Here's an example of a migration we may need to run:

public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('username')->nullable()->unique();
    });
}

This migration is located at database/migrations/2024_05_09_111656_add_username_to_users_table.php. With this, you're able to specify the migration you want to run with the --path option:

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

You're also able to provide multiple comma-separated paths to the --path option, allowing you to run more than one specific migration file:

php artisan migrate --path=/database/migrations/2024_05_09_111656_add_username_to_users_table.php,/database/migrations/2024_09_12_000001_create_customer_columns.php

So, it's as easy as that to run a specific migration in Laravel. Just use the --path option and provide the paths to the migration files you want to run.

If you found this article helpful, you'll love our practical screencasts.
Author
Alex Garrett-Smith
Share :

Comments

No comments, yet. Be the first!

Tagged under