RENAMING COLUMNS IN MIGRATION

[norebro_social_networks icon_layout=”boxed”]

If you are using Laravel then code the laravel way or go back to plain php .

Scenario

You have created a column with type Integer and looking around to change it to String. You may think of the below solutions

1. Running raw query using DB::statement or DB::select.

2. Drop the column and create a new one with type String.

I am sure you will go with second solutions if you are a true laravel lover. If you are trying to do something like below in your migration file think again.

Schema::table('content', function(Blueprint $table)
 {
      $table->dropColumn("description");
      $table->string("description",50);
 
 });

It will give you error Column already exist because you are doing drop and add on the same instance before committing the drop statement

Schema will commit the changes you did to the table after the last statement so something like below will work.

Schema::table('content', function(Blueprint $table)
{
            $table->dropColumn("description");
 
});
 
Schema::table('content', function(Blueprint $table)
{
            $table->string("description",50);
});

Thanks

KodeInfo

https://www.kodeinfo.com
Comments to: RENAMING COLUMNS IN MIGRATION

    Your email address will not be published. Required fields are marked *

    Attach images - Only PNG, JPG, JPEG and GIF are supported.

    Stay connected

    Categories

    Newsletter

    Tags

    Recent Comments

      Recent Posts

      Recent Comments

        Archives

        Categories

        Meta