Posted On:

Posted In:

Laravel Migration is a version-controlling system for the database. Migration helps developers to modify the database and share it across a platform. This is an integral part of the Laravel web

development. You can easily alter database schema and track records of every update using Migration. This tutorial teaches you how to use migration in the Laravel framework.

Step 1:

To create a new migration, run the following command: 

php artisan migrate: make create_users_table 

You will find your migration file inside the application/migrations directory.

Step 2:

Create table schema in the up() method of this file.

 public  function up(){ 

       Schema::create(‘users’, function (Blueprint $table){ 

           $table->bigIncrements(‘id’); 

           $table->string(‘user_name’,32)->nullable(); 

           $table->string(’email’); 

           $table->string(‘password’); 

           $table->timestamps(); 

       }); 

} 

Step 3:

To execute all the migrations, run: php artisan migrate 

Laravel allows you to rollback previous migrations you’ve made.

To rollback the last migration, run: php artisan migrate: rollback

If migration does not rollback automatically, then run: php artisan migrate: reset

You can run specific migrations using this command:

 php artisan migrate –path=/database/migrations/my_migration.php

Conclusion

This tutorial shed some light on Laravel Migration and how you can use it in your project. Migrations might seem like an additional task at first; but when you understand it thoroughly, migrations will provide great help to track your database updates. 

If you are looking for a software firm to create your business website or mobile app, your search ends here. We build affordable and robust software solutions for businesses to digitally thrive on. Contact us to get a quote. You can mail us at [email protected] or WhatsApp us on +91 95 37 84 38 39. 

Latest Posts

WordPress Security Shield: The Ultimate 2024 Hack Prevention Guide

March 19, 2024

As the most used content management system (CMS), WordPress security shield is crucial. Creating a robust security system for your WordPress websites helps protect sensitive financial details and user information. Therefore, this ultimate 2024 hack…

Block Editor vs Divi vs Elementor: Choosing Best WordPress Builder

March 13, 2024

A few years back website creation demanded a lot of technical knowledge and proficiency in HTML, CSS, and JavaScript. The scenario has changed, building a user-friendly website with no code is possible. Today, a variety…

Leave a Reply

Your email address will not be published. Required fields are marked *