fjurr
fjurr

Reputation: 552

Error NULL DEFAULT NULL Laravel migration with MariaDB

I have the following migration, where I'm adding an extra column in a table:

<?php

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

class AddTenantIdToPeopleTable extends Migration
{
    public function up()
    {
        /*
        * Need to create the column as null and then mark it as non-null to
        * avoid SQLite problem General error: 1 Can not add to NOT NULL column with default value NULL
        */

        Schema::table('people', function (Blueprint $table) {
            $table->integer('tenant_id')->nullable()->unsigned();
            $table->index('tenant_id');
        });

        Schema::table('people', function (Blueprint $table) {
            $table->integer('tenant_id')->nullable(false)->change();
        });
    }

    public function down()
    {
        Schema::disableForeignKeyConstraints();
            Schema::table('people', function (Blueprint $table) {
                $table->dropColumn('tenant_id');
            });
        Schema::enableForeignKeyConstraints();
    }
}

I can run this migration with PostgreSQL, SQLite and MySQL without any errors, but when I try to run with Maria DB, this error happens:

Error

I tried some things but nothing works.

Upvotes: 0

Views: 1464

Answers (1)

fjurr
fjurr

Reputation: 552

I've managed to get this thing working. I just added the "->default(null)"

I did this:

public function up()
    {
        Schema::table('people', function (Blueprint $table) {
            $table->integer('tenant_id')->nullable()->unsigned();
            $table->index('tenant_id');
        });

        Schema::table('people', function (Blueprint $table) {
            $table->integer('tenant_id')->nullable(false)->default(null)->change();
        });
    }

Upvotes: 1

Related Questions