laravel
  1. laravel-migration

Migration - Laravel Migration

Laravel Migration is a database migration system that allows developers to version control the database schema. It helps to keep track of changes made to the database schema over time and makes it easier to work in a team environment. In this article, we'll explore Laravel Migration in detail.

Laravel Migration

Syntax

To create a migration, use the following command:

php artisan make:migration migration_name --create=table_name

To run the migration, use the following command:

php artisan migrate

To rollback a migration, use the following command:

php artisan migrate:rollback

Example

Here is an example of a migration that creates a users table:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

Output

When you run the migration, Laravel will create a users table with the specified schema.

Explanation

Laravel Migration is a system for version controlling the database schema. Each migration is a new version of the database schema. Migrations allow you to easily add or remove tables and columns from the database schema, without having to manually update each instance of your application.

Use

Laravel Migration is useful in any project that involves a database. It allows developers to version control the database schema, making it easier to work in a team environment. It also allows them to easily make changes to the schema without having to manually update each instance of their application.

Important Points

  • Migrations are version controls for the database schema.
  • Each migration is a new version of the database schema.
  • Laravel Migration is useful in any project that involves a database.

Summary

In this article, we explored Laravel Migration, a database migration system that allows developers to version control the database schema. We covered the syntax and demonstrated an example of creating a users table. We also discussed its use cases and important points to keep in mind. By using Laravel Migration, developers can easily version control the database schema and make changes to it without having to manually update each instance of their application.

Published on: