remove Default in migration?

Surprisingly or not, for NOT NULL fields ->default(null) removes the default from a table:

public function up()
{
    Schema::table('client', function (Blueprint $table) {
        $table->boolean('enabled')->default(null)->change();
    });
}

Just omitting the default() part doesn't work, since laravel makes a diff between current state and current state + specified changes. No changes specified, no diff.

After that, doctrine generates ALTER TABLE statement, treating NULL as no default value.

With nullable fields though, from what I can see, doctrine doesn't let you simply drop the default. The only option is supposedly to make them NOT NULL:

public function up()
{
    Schema::table('client', function (Blueprint $table) {
        $table->boolean('enabled')->nullable(false)->default(null)->change();
    });
}

Maybe with PostgreSQL you can get away without converting to NOT NULL, but that's to be confirmed.


Since there is no way to remove this statement with Laravel functions, your down function must execute the statement as raw. It should be something like:

public function down()
  {
    Schema::table('client', function ($table) {
      DB::statement('ALTER TABLE' . $table . 'ALTER COLUMN enabled DROP DEFAULT');
    });
  }

In order to execute this migration, you need to incluide at the top of your migration:

use Illuminate\Support\Facades\DB;