Get "PHP 8 in a Nuthshell" (Now with PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Rollback a specific migration in Laravel

There comes a time when you want to make some changes to an existing table. For instance, you want to change the data type of a column. So, in this case, you can modify the migration file of the table and then run the migration again using the artisan migrate:refresh command like so.

php artisan migrate:refresh

But what this will do is that it will rollback all the migrations and then run them again. Essentially, this command effectively re-creates your entire database. And you might not want to do that.

So,

If you only want to rollback a specific migration, you can pass in a --path option to the artisan migrate:refresh command and specify the path to the migration file you want to rollback.

For instance, if you want to rollback the 2014_10_12_100000_create_password_resets_table migration, you can do so like so.

php artisan migrate:refresh --path=database/migrations/2014_10_12_100000_create_password_resets_table.php

Here’s what this might look like.

php artisan migrate --path

As you can tell, this will only rollback the 2014_10_12_100000_create_password_resets_table migration and then run it again leaving the rest of the migrations untouched.

Learn the fundamentals of PHP 8 (including 8.1, 8.2, 8.3, and 8.4), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?