How to Reexecute Migration Script in Laravel Using PHP Artisan Command

Posted on

This is an article written to demonstrate how to reexecute all the migration script files in Laravel web-based application development. Actually, it is only working as far as I know in the Laravel since the tool or the utility provided is available only in Laravel web-based application development. Maybe this feature also available within another PHP Programming Framework used but in this article the focus will only be in the Laravel PHP Framework.

The tool or the utility mentioned previously which is available in Laravel web-based application development is ‘artisan’. It exists as soon as the project based on Laravel has already generated successfully. The main point is the focus of this article which is only showing how to re-execute migration script in Laravel web-based framework. It is important if the migration script file is being changed or it is being modified. The impact for changing or modifying the migration script file is in order it can be implemented, it must be re-executed once more.

It must be re-executed once more so that the changes or the modification can be implemented in the form of the associated tables. Below are steps taken to achieve it :

1. Change the corresponding tables by editing it with any text editor available.

2. Run the following command to be able to re-execute all of the migration script files available normally in the folder ‘/database/migrations’. The command is shown as follows :

php artisan migrate:refresh

If it is executed in the real condition or situation, it will be shown as the following output :

root@hostname:/var/www/html/laravel# php artisan migrate:refresh
Rolling back: 2017_11_03_095254_create_units_table
Rolled back: 2017_11_03_095254_create_units_table
Rolling back: 2017_11_03_060734_create_services_table
Rolled back: 2017_11_03_060734_create_services_table
Rolling back: 2017_11_02_154132_create_comments_table
Rolled back: 2017_11_02_154132_create_comments_table
Rolling back: 2017_11_02_151921_create_categories_table
Rolled back: 2017_11_02_151921_create_categories_table
Migration not found: 2017_11_02_151257_create_categories_table
Migration not found: 2017_11_02_150646_create_categories_table
Rolling back: 2017_11_02_150552_create_tickets_table
Rolled back: 2017_11_02_150552_create_tickets_table
Rolling back: 2014_10_12_100000_create_password_resets_table
Rolled back: 2014_10_12_100000_create_password_resets_table
Rolling back: 2014_10_12_000000_create_users_table
Rolled back: 2014_10_12_000000_create_users_table
[BadMethodCallException]
Method increment does not exist.
root@hostname:/var/www/html/laravel#

Those are the output generated and the output can be differ from one laravel web-based application to another depends on the available migration script files available inside the folder.

One thought on “How to Reexecute Migration Script in Laravel Using PHP Artisan Command

Leave a Reply