Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: migrations change default value(boolean) of column

This is my current code.

public function up()
{
    Schema::table('render', function (Blueprint $table) {
        $table->boolean('displayed')->default(1);
    });
}`

How to change the default value to 0 as below?

public function up()
{
    Schema::table('render', function (Blueprint $table) {
        $table->boolean('displayed')->default(0);
    });
}
like image 546
Tomeikun Avatar asked Dec 12 '25 06:12

Tomeikun


2 Answers

public function up()
{
    Schema::table('render', function (Blueprint $table) {
        $table->boolean('displayed')->default(0)->change();
    });
}

Added ->change(). Please see Link

like image 58
Ganesh Ghalame Avatar answered Dec 14 '25 04:12

Ganesh Ghalame


Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->boolean('is_active')->unsigned()->nullable();
    $table->timestamps();
});

is_active column is defined as a nullable boolean column using the boolean data type and the unsigned modifier. This will allow you to use the true and false keywords in your database queries instead of 0 and 1.

like image 45
Muhammad Hassan Saleem Avatar answered Dec 14 '25 03:12

Muhammad Hassan Saleem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!