Search code examples
laravellaravel-8placeholderupsert

SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders Laravel 8 upsert


Getting error

SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders...

while upsert large data.

Here is my code:

$reportItem = ReportItem::upsert($data->toArray(), ['someId','otherId']);

I think this limit because of mysql and i tried to use chunk but no success. Any help?

$reportItem = ReportItem::chunk(1000, upsert($data->toArray(), ['someId','otherId']));

Solution

  • You need to chunk the "$data" collection to be inserted.

    foreach ($data->chunk(100) as $chunk) {
        ReportItem::upsert($chunk->toArray(), ['someId','otherId']);
    }