laravel/framework · error · RuntimeException
This database engine does not support inserting while ignori
Error message
This database engine does not support inserting while ignoring errors.
What it means
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.
Source
Thrown at src/Illuminate/Database/Query/Grammars/Grammar.php:1275
$parameters = (new Collection($values))
->map(fn ($record) => '('.$this->parameterize($record).')')
->implode(', ');
return "insert into $table ($columns) values $parameters";
}
/**
* Compile an insert ignore statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*
* @throws \RuntimeException
*/
public function compileInsertOrIgnore(Builder $query, array $values)
{
throw new RuntimeException('This database engine does not support inserting while ignoring errors.');
}
/**
* Compile an insert or ignore statement with a returning clause into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @param array $returning
* @param array|null $uniqueBy
* @return string
*
* @throws \RuntimeException
*/
public function compileInsertOrIgnoreReturning(Builder $query, array $values, array $returning, ?array $uniqueBy)
{
throw new RuntimeException('This database engine does not support insert or ignore with returning.');
}
View on GitHub (pinned to bd6b5437e6)
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.
Example fix
// before
DB::table('tags')->insertOrIgnore($rows);
// after (SQL Server compatible)
foreach ($rows as $row) {
DB::table('tags')->insertOrIgnore([$row]);
}
// or pre-check:
DB::table('tags')->insert(
collect($rows)->filter(fn ($r) => ! DB::table('tags')->where('name', $r['name'])->exists())->all()
); Defensive patterns
Strategy: validation
Validate before calling
$driver = DB::getDriverName();
if ($driver === 'sqlsrv') {
throw new \LogicException('insertOrIgnore is not supported on SQL Server; pre-check duplicates.');
}
DB::table('tags')->insertOrIgnore($rows); Type guard
function supportsInsertOrIgnore(\Illuminate\Database\Connection $connection): bool
{
return ! ($connection instanceof \Illuminate\Database\SqlServerConnection);
} Prevention
- 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.
When it happens
Trigger: Calling DB::table(..)->insertOrIgnore($values) (or Model::insertOrIgnore) on a sqlsrv connection.
Common situations: 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.
Related errors
- This database engine does not support insert or ignore with
- This database engine does not support case sensitive like op
- This database engine does not support fulltext search operat
- Cannot use saveOrIgnore on an existing model.
- The unique columns must not be empty.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/e172515511d006d5.json.
Report an issue: GitHub.