In the migration I alter enabled
field to set to 1 value as default.
public function up() { Schema::table('client', function (Blueprint $table) { $table->boolean('enabled')->default(1)->change(); }); }
In down()
method - How do I remove default()
? I know can do default(0)
but default was never created during create table.
In our case we are going to do second option - create new migration. If we roll back this migration, we need to remove default value from that field using migration and this is how to do it: Schema::table('photos', function (Blueprint $table) { $table->integer('order')->default(NULL)->change(); });
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With