DB Migration – To change schema of a table

Command:

php artisan make:migration add_oi_preserved_order_table --table=orders

Migration Class:

<?php

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

class AddOiPreservedOrderTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->renameColumn('from', 'to');
            //Add column tag_id after password
            $table->string('tag_id')->after('password')->nullable();
            $table->integer('sell_rate')->nullable()->after('rate')->change();
            $table->decimal('oi_preserved', 10, 2)->nullable()->after('commissioned_price')->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropColumn('oi_preserved');
        });
    }
}

This package is required to change columns

composer require doctrine/dbal

Required PHP extension

  • extension=fileinfo
  • extension=pdo_mysql

Doc:

https://laravel.com/docs/5.4/migrations#creating-columns