Introduction
This is an article where the main focus is to execute an existing migration script file. That file exist in a Laravel-based program. It exist after executing a simple command for creating the migration script file. The process for creating the migration script file exist in an article with the title of ‘How to Create Migration Script in Laravel’ in this link.
Execute Migration Script File in Laravel
So, what is the step for executing a migration script file in a Laravel-based project or application. The following below are the steps to achieve it :
-
First of all, off course the existence of the Laravel-based project or application is a must.
-
Second, the existence of the migration script file. In order to create it, just read the article with the title of ‘How to Create Migration Script in Laravel’ for reference in this link.
-
Next step, execute that migration script using the following command pattern :
php artisan migrate
-
So, execute it in the term of the following situation. The Laravel-based project or application exist in ‘C:\programming\php\laravel\crud’. Moreover, there is already a migration script file exist from the previous command execution. That command execution is for creating a migration script file. It has the name of ‘2021_08_03_124211_create_categories_table’ which exist in ‘C:\programming\php\laravel\crud\database\migrations’. According to those descriptions, the following is the actual execution :
C:\programming\php\laravel\crud> php artisan migrate Migration table created successfully. Migrating: 2014_10_12_000000_create_users_table Migrated: 2014_10_12_000000_create_users_table (1,544.55ms) Migrating: 2014_10_12_100000_create_password_resets_table Migrating: 2019_08_19_000000_create_failed_jobs_table Migrating: 2021_08_03_124211_create_categories_table Migrated: 2021_08_03_124211_create_categories_table (1,341.16ms) C:\programming\php\laravel\crud>
-
Finally, check the database for the newly created tables resulting from the above command execution. Access to the database and perform the following command. Considering the database name is ‘db_app_laravel’.
mysql> use db_app_laravel; Database changed mysql> show tables; +--------------------------+ | Tables_in_db_app_laravel | +--------------------------+ | categories | | failed_jobs | | migrations | | password_resets | | users | +--------------------------+ 8 rows in set (0.26 sec) mysql>
There is a table with the name of ‘categories’. So, the execution of the migration script file is a success.