Laravel 5 - Set fields to nullable on table create

709 Views Asked by At

I have a multi-tenant installation and am working with creating new hosts automatically. I am trying to simply set the Allow Null value on a table for each of the columns when the table is first created. This is not working but later migration files that add new columns to the existing table to work with setting them to nullable.

I am using the following to first create the table, null not set:

public function up()
{
    Schema::create('phone_logs', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('type')->nullable(true)->change();
        $table->string('groupId')->nullable(true)->change();
        $table->string('status')->nullable(true)->change();
        $table->string('status_code')->nullable(true)->change();
        $table->longText('message')->nullable(true)->change();
        $table->string('sender')->nullable(true)->change();
        $table->string('receiver')->nullable(true)->change();
        $table->string('contactNumber')->nullable(true)->change();
        $table->dateTime('date')->nullable(true)->change();
        $table->string('messageUID')->nullable(true)->change();
        $table->integer('has_read')->nullable(true)->change();
        $table->string('lists_sent')->nullable(true)->change();
        $table->string('user_id')->nullable(true)->change();
        $table->string('audio')->nullable(true)->change();
        $table->timestamps();
    });
}

Then using this to add 3 new columns to the table and it does set null:

public function up()
{
    Schema::table('phone_logs', function (Blueprint $table) {
        //
        $table->string('reply_numbers')->nullable(true);
        $table->text('auto_response_1')->nullable(true);
        $table->dateTime('schedule_date')->nullable(true);
    });
}

I added ->change() after reading a few suggestions and also included nullable(true) instead of just nullable() as that was suggested as well but still doesn't set and requires me to do so manually.

0

There are 0 best solutions below