Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel migrations change a column type from varchar to longText

I need to change with a migration column type of $table->string('text'); to a text type, I have tried to do that in a few ways, but none of them worked. Is it possible to do it in one migration? I could I guess drop the column and then create it again with a new type, but I wonder if it is possible to do it in one migration?

like image 845
Ludwig Avatar asked Jun 09 '16 11:06

Ludwig


People also ask

How do I change a column to unique in Laravel migration?

$table->unique('slug'); So you add unique index to existing 'slug'.

How do I change a column to nullable in Laravel migration?

The code to change the column to nullable is as "nullable()->change()". ->nullable()->change();


1 Answers

You can create a new migration and change just one column type:

public function up() {     Schema::table('sometable', function (Blueprint $table) {         $table->text('text')->change();     }); } 

You need to install doctrine/dbal to make this work

composer require doctrine/dbal 

Works with Laravel 5.0+. It does not work with Laravel 4.2.

like image 124
Alexey Mezenin Avatar answered Oct 14 '22 18:10

Alexey Mezenin