6 min read

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 info@qrolic.com or WhatsApp us on +91 95 37 84 38 39. 

"Have WordPress project in mind?

Explore our work and and get in touch to make it happen!"