1
votes

I'm trying to run a migration on Laravel for creating a new table, but I'm getting this error:

Syntax error or access violation: 1067 Invalid default value for 'tracked_product_id'

I understand there is an issue with the first unsignedInteger line - I have attempted to change this default value but it returns the same error when attempting to migrate.

Here is the up function that I am trying to migrate:

public function up()
{
    Schema::create('tracked_product_notes', function (Blueprint $table) {
        $table->increments('id');
        $table->unsignedInteger('tracked_product_id', true)->default(0);
        $table->unsignedInteger('user_id', true)->default(0);
        $table->string('note')->nullable();
        $table->timestamp('deleted_at');
        $table->timestamps();
    });
}

Any help would be greatly appreciated!

1
Change it to $table->unsignedInteger('tracked_product_id')->default(null); or $table->unsignedInteger('tracked_product_id')->nullable(); - sta
Apologies, I forgot to reply at the time. This fixed my issue, thanks Droid! - RyanDawkes

1 Answers

0
votes

Change it to :

$table->unsignedInteger('tracked_product_id')->default(null); 

or

$table->unsignedInteger('tracked_product_id')->nullable();