Removing database migration script file in PHP Laravel 5

Posted on

Removing database migration script file in Laravel 5

Programming Language                     : PHP

Framework                                         : Laravel 5

Operating System                         : Ubuntu 16.04 (Xenial Xerus).  It is working for operating sytem which has command line interface

When we try to develop a web-based application with PHP programming language with Laravel Framework, we can use PHP artisan tool to generate script which can be used to generate database.

But sometime, we also need to remote the script and also the status of that database migration script file laravel project database migrations’ table.

  1. Check the migration status

We actually can check it by executing the command as part of utility that is provided by Laravel which is the PHP artisan. Just type the following command :

php artisan:migrate status

For an example:

username@hostname:/var/www/html/laravel_project# php artisan migrate:status
+------+----------------------------------------------------+
| Ran? | Migration                                          |
+------+----------------------------------------------------+
| Y    | 2014_10_12_000000_create_users_table               |
| Y    | 2014_10_12_100000_create_password_resets_table     |
| Y    | 2016_07_07_113807_create_projects_and_tasks_tables |
+------+----------------------------------------------------+
  1. Remove the database migration script file

The database migration script file is located in :

database/migrations
username@hostname:/var/www/html/laravel_project# cd database/migrations/
username@hostname:/var/www/html/laravel_project/database/migrations# rm -rf 2016_07_07_113807_create_projects_and_tasks_tables.php
username@hostname:/var/www/html/laravel_project/database/migrations# cd ..
username@hostname:/var/www/html/laravel_project/database# cd ..
  1. Execute the following command to reupdate the database migration script files by typing the following command :
username@hostname:/var/www/html/laravel_project# composer dump-autoload
Running composer as username/super user is highly discouraged as packages, plugins and scripts cannot always be trusted
Generating autoload files
username@hostname:/var/www/html/laravel_project#
  1. We can also check the following command to check the database migration script file after removing the script :
php artisan migrate:status
root@hostname:/var/www/html/laravel_project# php artisan migrate:status
+------+------------------------------------------------+
| Ran? | Migration                                      |
+------+------------------------------------------------+
| Y    | 2014_10_12_000000_create_users_table           |
| Y    | 2014_10_12_100000_create_password_resets_table |
+------+------------------------------------------------+
username@hostname:/var/www/html/laravel_project#

As we can see, the database migration script file which has been registered or listed only remain two files. The third record has been erased while erasing the database migration script file and executed ‘composer dump-autoload’ to update status. We have to also drop the table which has been generated by executing the database migration script file by executing ‘php artisan migrate’. Dropping the table is necessary if only we want to generate the table again.

One thought on “Removing database migration script file in PHP Laravel 5

Leave a Reply