Laravel migration table field's type change
update: 31 Oct 2018, Still usable on laravel 5.7 https://laravel.com/docs/5.7/migrations#modifying-columns
To make some change to existing db, you can modify column type by using change()
in migration.
This is what you could do
Schema::table('orders', function ($table) { $table->string('category_id')->change();});
please note you need to add doctrine/dbal dependency to composer.jsonfor more information you can find it here http://laravel.com/docs/5.1/migrations#modifying-columns
The standard solution didn't work for me, when changing the type from TEXT to LONGTEXT.
I had to it like this:
public function up(){ DB::statement('ALTER TABLE mytable MODIFY mycolumn LONGTEXT;');}public function down(){ DB::statement('ALTER TABLE mytable MODIFY mycolumn TEXT;');}
This could be a Doctrine issue. More information here.
Another way to do it is to use the string() method, and set the value to the text type max length:
Schema::table('mytable', function ($table) { // Will set the type to LONGTEXT. $table->string('mycolumn', 4294967295)->change(); });
2018 Solution, still other answers are valid but you dont need to use any dependency:
First you have to create a new migration:
php artisan make:migration change_appointment_time_column_type
Then in that migration file up()
, try:
Schema::table('appointments', function ($table) { $table->string('time')->change(); });
If you donot change the size default will be varchar(191)
but If you want to change size of the field:
Schema::table('appointments', function ($table) { $table->string('time', 40)->change(); });
Then migrate the file by:
php artisan migrate