laravel/framework · error · RuntimeException
This database driver does not support dropping foreign keys…
Error message
This database driver does not support dropping foreign keys by name.
What it means
SQLiteGrammar::compileDropForeign throws when $command->columns is empty because SQLite tracks foreign keys only by the column(s) they sit on, not by an internally named constraint. Blueprint->dropForeign(['name']) on SQLite has no way to map the name to a constraint, so the framework requires you to drop by column name instead.
Solutions
- Drop the foreign key by its column name(s) on SQLite: $table->dropForeign(['user_id']).
- Branch the drop by driver: pass a name on Postgres/MySQL and a columns array on SQLite.
- If you must support both, write the migration to inspect getDriverName() and call dropForeign with the appropriate argument shape.
Example fix
// before
$table->dropForeign('orders_user_id_foreign');
// after (portable)
use Illuminate\Support\Facades\DB;
if (DB::connection()->getDriverName() === 'sqlite') {
$table->dropForeign(['user_id']);
} else {
$table->dropForeign('orders_user_id_foreign');
} Defensive patterns
Strategy: validation
Validate before calling
use Illuminate\Support\Facades\DB;
if (DB::connection()->getDriverName() === 'sqlite') {
$table->dropForeign(['user_id']); // columns
} else {
$table->dropForeign('orders_user_id_foreign'); // named constraint
} Type guard
function dropForeignArgsForDriver(string $driver, string|array $byName, array $byColumns): string|array {
return $driver === 'sqlite' ? $byColumns : $byName;
} Prevention
- On SQLite, always pass the column name(s) to dropForeign, never the constraint name.
- Branch foreign-key drops by driver in shared migrations.
- Document the SQLite restriction in the migration header comment.
When it happens
Trigger: Calling $table->dropForeign('some_foreign_key_name') (a string name, which the blueprint maps to an empty columns array) on a SQLite connection.
Common situations: Writing portable migrations that drop foreign keys by constraint name (the Postgres/MySQL idiom) and running them on SQLite in tests; down migrations that call dropForeign with the original index name.
Related errors
- SQLite does not support altering primary keys.
- The database driver in use does not support spatial indexes.
- This database driver requires a type, see the virtualAs /…
- Index [ ] does not exist.
- This database driver does not support modifying generated…
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/47baab0ed6225bf2.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php:607
*/
public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
{
throw new RuntimeException('The database driver in use does not support spatial indexes.');
}
/**
* Compile a drop foreign key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return array
*
* @throws \RuntimeException
*/
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
{
if (empty($command->columns)) {
throw new RuntimeException('This database driver does not support dropping foreign keys by name.');
}
// Handled on table alteration...
}
/**
* Compile a rename table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileRename(Blueprint $blueprint, Fluent $command)
{
$from = $this->wrapTable($blueprint);
return "alter table {$from} rename to ".$this->wrapTable($command->to);
}View on GitHub (pinned to e0f6eb3518)