RENAMING COLUMNS IN MIGRATION
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
No Comments
Leave a comment Cancel