5
votes

As per laravel doc, To rollback the latest migration operation, you may use the rollback command. This command rolls back the last "batch" of migrations, which may include multiple migration files:

php artisan migrate:rollback

You may rollback a limited number of migrations by providing the step option to the rollback command. For example, the following command will rollback the last five migrations:

php artisan migrate:rollback --step=5

The migrate:reset command will roll back all of your application's migrations:

php artisan migrate:reset

You can check here. But i need to remove the specific migration file. As per my project having 30-40 migration file. I want to remove one of the migration file and its model. Is there any way to do this or have to do it manually.

5
What @GovindSamrow shared is what you are looking for. But In my opinion, deleting a migration is never a good idea. Alternatively, you should write another migration which changes your db structure according to your new requirements. We must remember migrations provide 'version controlled database'. Deleting, although possible, is just against the concept of migrations. And we must avoid that especially in larger projects such as yours.Nauman Zafar

5 Answers

1
votes

Just do it manually and save yourself the stress of further issues

  1. Delete the model first (if you don't) need the model any longer
  2. Delete the migration from ...database/migrations folder
  3. If you have already migrated i.e if you have already run php artisan migrate, log into your phpmyadmin or SQL(whichever the case is) and in your database, delete the table created by the migration
  4. Still within your database, in the migrations folder, locate the row with that migration file name and delete the row.

Works for me, hope it helps!

1
votes

Don’t. Migrations are version control for your database. “Removing” a particular migration is like removing a random commit from your Git repository’s history: it can have terrible consequences.

Instead, if you no longer need a table, then create a new migration that drops that table in the up method, and recreates it in the down method so the migration can be rolled back.

0
votes

If you simply remove (delete) the migration file and re-run the migrations (migrate:refresh), the database tables will be rebuilt (without the table that's defined in the migration file you deleted).

0
votes

Delete the migration file, remove the table from the database, and also remove that file name from migrations table in the database.

Sometimes, doing things manually is the best way.

0
votes

you can increment the batch number of that particular migration to make it latest batch and run rollback command. Rollback one specific migration in Laravel