Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove specific migration in laravel

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.

like image 326
CodeBriefly Avatar asked Oct 17 '22 10:10

CodeBriefly


2 Answers

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.

like image 190
Martin Bean Avatar answered Oct 21 '22 07:10

Martin Bean


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.

like image 26
fred Avatar answered Oct 21 '22 08:10

fred