In this tutorial you will learn about the How to Increase Column Size using Laravel Migration and its application with practical example.
In this tutorial, we will learn how to change column length using laravel migration. It is easy to change column length using laravel migration. We will use laravel migration to change column length.
Table Of Contents−
Create Table Migration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateBlogsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('blogs', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('title', 50); $table->text('body'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('blogs'); } } |
Change Column Length using Migration
Now, we will change title string length 50 to 100. We will use laravel migration to change column length. We will following composer package before creating change column length migration:
Install Composer Package
1 |
composer require doctrine/dbal |
Change Column Length Migration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class UpdateBlogsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('blogs', function (Blueprint $table) { $table->string('title', 100)->change(); }); } /** * Reverse the migrations. * * @return void */ public function down() { } } |