0

i am working on laravel application. A small change in database table cause fresh migration. is there any method to re migrate only on table in laravel.

Zia
  • 76
  • 2
  • 11
  • 1
    Possible duplicate of [how can i run specific migration in laravel](https://stackoverflow.com/questions/47151886/how-can-i-run-specific-migration-in-laravel) – fubar Nov 06 '18 at 02:57
  • 2
    Possible duplicate of [Laravel 5.4 Specific Table Migration](https://stackoverflow.com/questions/45473624/laravel-5-4-specific-table-migration) – Kapitan Teemo Nov 06 '18 at 04:38
  • You can alter the table with the changes using another migration right ? – Ijas Ameenudeen Nov 06 '18 at 04:54

2 Answers2

7

Just look at the migrations table in your database, there will be a list of migration file name and batch number value.

Suppose you have following structure,

id-------------------------migration---------------------------batch

1----------2014_10_12_000000_create_users_table---------------- 1

2----------2014_10_12_100000_create_password_resets_table-------1

3----------2016_09_07_103432_create_tabel_roles-----------------1

If you want to just rollback 2016_09_07_103432_create_tabel_roles migration, change it's migration batch value to 2 which is highest among all and then just execute following.

php artisan migrate:rollback

Here only table with batch value 2 will be rolled back. Now make changes to that table and run following console command.

php artisan migrate

Batch value in the migrations table defines order of the migrations. when you rollback, migrations that are latest or have highest batch value are rolled back at first and then others. So, you can change the value in database and then rollback a particular migration file.

Although it's not a good idea to change batch number every time because of relationship among the table structure, we can use this case for some cases where single table rollback doesn't violates the integrity among the tables.

Hope you understand.

0

You can use below command to re-migrate the all table.

Documents: https://laravel.com/docs/5.7/migrations

php artisan migrate:refresh