'Inserting new entries with Laravels upsert function with no key

I am trying to pass an array that has both existing and new rows I would like to insert into my QueueLane model by using laravel upsert function.

The code:

QueueLane::upsert([
    ['name' => 'Existing Lane Update', 'id' => 5],
    ['name' => 'A New Lane', 'id' => null]
], ['id'], ['name']);

You can see the first row has an id, so I want to update the name column with whatever value is in the array, the second row, however, doesn't have an id so I want this record to be created.

When running the code I get the following error:

null value in column "id" violates not-null constraint

I'm expecting the Laravel to populate the ID with a new auto incrementing integer as is the usual behavior for new records in the Model.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source