phplaravellaravel-migrations

Rollback Failed Laravel Migration


I have more than once been in the situation where I'll be working on a migration, and the up() function fails. I would like the use the down() function of that migration, but running php artisan migrate:rollback --file=/database/migrations/2024_09_13_200633_example.php doesn't work because of the failure.

How do I arbitrarily run the down() portion of a migration?


Solution

  • With the current anonymous migrations, the files return an instance of the class. Calling any method of the migration is as simple as running it like this in the Artisan Console:

    (include 'database/migrations/2024_09_13_200633_example.php')->down();