Home > Back-end >  SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders Laravel 8 ups
SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders Laravel 8 ups

Time:11-16

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']));

CodePudding user response:

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

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