{"id":"e172515511d006d5","repo":"laravel/framework","slug":"this-database-engine-does-not-support-inserting-wh","errorCode":null,"errorMessage":"This database engine does not support inserting while ignoring errors.","messagePattern":"This database engine does not support inserting while ignoring errors\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Grammars/Grammar.php","lineNumber":1275,"sourceCode":"        $parameters = (new Collection($values))\n            ->map(fn ($record) => '('.$this->parameterize($record).')')\n            ->implode(', ');\n\n        return \"insert into $table ($columns) values $parameters\";\n    }\n\n    /**\n     * Compile an insert ignore statement into SQL.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  array  $values\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    public function compileInsertOrIgnore(Builder $query, array $values)\n    {\n        throw new RuntimeException('This database engine does not support inserting while ignoring errors.');\n    }\n\n    /**\n     * Compile an insert or ignore statement with a returning clause into SQL.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  array  $values\n     * @param  array  $returning\n     * @param  array|null  $uniqueBy\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    public function compileInsertOrIgnoreReturning(Builder $query, array $values, array $returning, ?array $uniqueBy)\n    {\n        throw new RuntimeException('This database engine does not support insert or ignore with returning.');\n    }\n","sourceCodeStart":1257,"sourceCodeEnd":1293,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Grammars/Grammar.php#L1257-L1293","documentation":"The base Grammar::compileInsertOrIgnore() throws because this engine has no INSERT IGNORE equivalent. SQLite, MySQL, and Postgres override compileInsertOrIgnore; SQL Server does not, so insertOrIgnore() on SQL Server reaches this base throw.","triggerScenarios":"Calling DB::table(..)->insertOrIgnore($values) (or Model::insertOrIgnore) on a sqlsrv connection.","commonSituations":"Sharing seeding/import code that uses insertOrIgnore between a MySQL/Postgres app and a SQL Server deployment. Running cross-engine migrations that intentionally ignore duplicate-key errors.","solutions":["On SQL Server, wrap the insert in a try/catch around the duplicate-key error (2627/2601) or use a MERGE/NOT EXISTS pre-check.","Pre-filter rows with a WHERE NOT EXISTS subquery before inserting.","Restrict insertOrIgnore usage to MySQL/Postgres/SQLite connections."],"exampleFix":"// before\nDB::table('tags')->insertOrIgnore($rows);\n\n// after (SQL Server compatible)\nforeach ($rows as $row) {\n    DB::table('tags')->insertOrIgnore([$row]);\n}\n// or pre-check:\nDB::table('tags')->insert(\n    collect($rows)->filter(fn ($r) => ! DB::table('tags')->where('name', $r['name'])->exists())->all()\n);","handlingStrategy":"validation","validationCode":"$driver = DB::getDriverName();\nif ($driver === 'sqlsrv') {\n    throw new \\LogicException('insertOrIgnore is not supported on SQL Server; pre-check duplicates.');\n}\nDB::table('tags')->insertOrIgnore($rows);","typeGuard":"function supportsInsertOrIgnore(\\Illuminate\\Database\\Connection $connection): bool\n{\n    return ! ($connection instanceof \\Illuminate\\Database\\SqlServerConnection);\n}","tryCatchPattern":null,"preventionTips":["On SQL Server, use WHERE NOT EXISTS or MERGE for idempotent inserts.","Branch import/seed code by driver.","Test seeding paths on all target engines."],"tags":["insert-ignore","sqlsrv","database-engine","insert"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}