1

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!

RyanDawkes
  • 47
  • 5
  • Change it to `$table->unsignedInteger('tracked_product_id')->default(null);` or `$table->unsignedInteger('tracked_product_id')->nullable();` – STA Feb 22 '21 at 17:57
  • Apologies, I forgot to reply at the time. This fixed my issue, thanks Droid! – RyanDawkes Mar 17 '21 at 09:29

1 Answers1

0

Change it to :

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

or

$table->unsignedInteger('tracked_product_id')->nullable();
STA
  • 30,729
  • 8
  • 45
  • 59