Introduction
This article will show how to create a migration script in a Laravel-based project or application. Actually, it is very easy to make a migration script in Laravel-based project. The requirement is just to have a Laravel-based project. After that, creating a migration script will be possible by using the tool available in the Laravel-based project. So, after creating a migration script file, just execute it in order to manipulate the database for further usage in the Laravel-based project or application.
How to Create Migration Script in Laravel
So, what is the actual step for creating a migration script in Laravel-based project or application ?. Just follow the steps below :
-
First of all, the actual Laravel-based project. Look at the article with the title of ‘How to Create a Laravel Project using Composer in Microsoft Windows’ in this link for reference.
-
Next, just access any command line interface available.
-
Go through the root path of the Laravel-based project. In this case for an example, it exist in ‘C:\programming\php\laravel\crud’.
-
In that path, try to execute the following command pattern :
php artisan make:migration migration_file_name
Just execute the above command pattern as the following example to create a new migration script file as follows :
Copyright (C) Microsoft Corporation. All rights reserved. C:\programming\php\laravel\crud> php artisan make:migration create_categories_table Created Migration: 2021_08_03_124211_create_categories_table C:\programming\php\laravel\crud>
-
If the above command is a success without generating any further error messages, just check the existence of the file. By default, it will be exist in a folder with the name of ‘database\migrations’. So, the full path location will be in : ‘C:\programing\php\laravel\crud\database\migrations’. Check the content, there will be a file with the name of ‘2021_08_03_124211_create_categories_table’ as follows :
C:\programming\php\laravel\crud\database\migrations>dir Volume in drive C is Windows Volume Serial Number is E003-3593 Directory of C:\programming\php\laravel\crud\database\migrations 08/01/2021 04:33 PM <DIR> . 08/01/2021 04:33 PM <DIR> .. 07/13/2021 09:12 PM 798 2014_10_12_000000_create_users_table.php 07/13/2021 09:12 PM 683 2014_10_12_100000_create_password_resets_table.php 07/13/2021 09:12 PM 820 2019_08_19_000000_create_failed_jobs_table.php 08/03/2021 12:42 PM 658 2021_08_03_124211_create_categories_table 4 File(s) 2,959 bytes 2 Dir(s) 2,245,812,224 bytes free C:\programming\php\laravel\crud\database\migrations>
As expected, the migration file script exist in that path as in the above output command.