run specific migration using artisan command from class

322 Views Asked by At

I tried to run a specific migration table from the controller using the following code Artisan::call ("migrate:refresh --step=14"); but it does not refresh table 14, on the other hand it refreshes all the tables .. , any suggestion !!

1

There are 1 best solutions below

3
On

That is the purpose of migrate:refresh. It rolls back the migrations and then runs them:

The migrate:refresh command will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database

You may roll back and re-migrate a limited number of migrations by providing the step option to the refresh command. For example, the following command will roll back and re-migrate the last five migrations

If you want to run run a specific migration the command would be:

migrate --path=/database/migrations/my_migration.php

This does however not sound like the best way to achieve whatever you are trying to achieve. Without further information it's hard to suggest an alternative plan for how to achieve this.

Edit: If you are trying to insert pre-defined data into a table you should look into using Database Seeders which sound much more to be what you are looking for.