Debug School

rakesh kumar
rakesh kumar

Posted on

How to migrate particular schema in laravel

php artisan migrate --path=database/migrations/2025_03_31_105055_create_challan_details_table.php
Enter fullscreen mode Exit fullscreen mode
php artisan migrate /opt/lampp/htdocs/motoshare.in/motoshare-web/database/migrations/2025_03_31_105055_create_challan_details_table.php
Enter fullscreen mode Exit fullscreen mode

Let’s break down this command step by step:

php artisan migrate:

php artisan: This is the command-line interface for Laravel, which provides a number of helpful commands to interact with your Laravel project.

migrate: This is the Artisan command that runs all the migrations that have not been run yet. A migration is a way to modify your database schema (create tables, add or remove columns, etc.) using PHP instead of SQL.

--

path=database/migrations/2025_03_31_105055_create_challan_details_table.php:
Enter fullscreen mode Exit fullscreen mode

--path: This option allows you to specify the location of a specific migration file (or directory) that you want to run. By default, php artisan migrate will run all pending migrations from the database/migrations directory.

database/migrations/2025_03_31_105055_create_challan_details_table.php: This is the relative path to the specific migration file you want to run. In this case:

database/migrations/ is the folder where all migration files are stored by default in Laravel.

2025_03_31_105055_create_challan_details_table.php is the filename of the migration. This file contains the instructions to create the challan_details table in the database.

What This Command Does:
The php artisan migrate command will normally run all migrations that have not been executed yet. However, with the --path option, you are telling Laravel to only execute a specific migration file instead of running all pending migrations.

The --path option is useful if you want to run a single migration or a specific set of migrations without affecting other migrations. For example, if you only want to run a migration that creates the challan_details table, you can specify just that migration using the --path option.

By providing the relative path (database/migrations/2025_03_31_105055_create_challan_details_table.php), you're telling Laravel to look for this specific migration file inside the database/migrations directory.

Example Use Case:
Suppose you have many migrations in your Laravel project, but you only want to run the migration for creating the challan_details table (for example, in the development or testing phase). Instead of running all migrations, you can run the migration for just that table:

php artisan migrate --path=database/migrations/2025_03_31_105055_create_challan_details_table.php
Enter fullscreen mode Exit fullscreen mode

This will execute only the create_challan_details_table migration and leave the other migrations untouched.

Top comments (0)