Daniel Gafitescu Freelance web developer focused on open source solutions

22Apr/150

Change field using migration on Laravel 4.2

If you have to change the type or in my case to add more options to the a ENUM field you need first to drop it and then to create it again (this will destroy the information in those field)


use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class UpdateTableNameStatus extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('table_name',function(Blueprint $table)
{
$table->dropColumn('status');
});

Schema::table('table_name',function(Blueprint $table)
{
$table->enum('status', array('PENDING','IN PROGRESS','COMPLETE'));

});

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('table_name',function(Blueprint $table)
{
$table->dropColumn('status');

});

Schema::table('table_name',function(Blueprint $table)
{
$table->enum('status', array('PENDING'));
});
}

}