How to Create Migration in Laravel 8 by using Command

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share
How to Create Migration in Laravel 8

Hello Dev’s
Now today, in this blog we will learn about how to create migrations by using Artisan .By using this it will create a new database table. We can take help of by using make:migration. Here we will know How to Create Migration in Laravel 8.

A migration class contains two methods: one is up and another one down. So the up method is used for add new tables, columns, or indexes to our database, and the down method should reverse the operations performed by the up method.

Example 1
php artisan make:migration create_demos_table

-> This command is used for create a new migration table in your project.

->It will create in database folder in migration folder.

database/migrations/2019_11_25_124745_create_demos_table.php

<?php

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

class CreateDemosTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('table', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->integer('user_id');
            $table->boolean('type')->default(0);
            $table->longText('address');
            $table->timestamps();
        });
    }

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

Create migration after use bellow command to migrate your table.

  php artisan migrate 
Example 2
  php artisan migrate:status

->Above command is used for table creation then after you can migrate or not.

->It will show List of table migration with migrate or not.

Example 3
  php artisan make:migration create_demos_table --create=demos

->This command is used to create table migration in your project.

->It will help you create migration your table.

Example 4
  php artisan migrate:rollback

->To rollback the latest migration operation, you may use the rollback command

->This command is used to edit your table migration.

->–step=5 : It will rollback the last five migrations.

Example 5
  php artisan migrate:refresh

-> This command is used to truncate your database table.

->–step=5 : It will truncate your last five database table.

Example 6
   php artisan make:migration create_demos_table --table=demos

->By the above command is used for create table migration.

->File created in your project.

Example 7.
  --path=Path

->This command is used for the location where the migration file should be created.

Example 8.
   php artisan make:migration create_demos_table --fullpath

->This command is used for output the full path of the migration.

Read Also : How to Disabled Specific dates and Friday,Saturday In Bootstrap Datepicker ?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →