laravel/framework · error · RuntimeException
This database driver does not support retrieving foreign…
Error message
This database driver does not support retrieving foreign keys.
What it means
Grammar::compileForeignKeys() throws RuntimeException on the base class; all four shipped grammars override it. Reaching the base means the connection's SchemaGrammar is the unimplemented base Grammar. Builder::getForeignKeys() routes here.
Solutions
- Use a supported driver (sqlite/mysql/pgsql/sqlsrv) for foreign-key introspection.
- Override compileForeignKeys($schema, $table) in your custom grammar.
- Query information_schema.table_constraints / pg_constraint directly.
Example fix
// before
$fks = Schema::connection('custom')->getForeignKeys('orders');
// after
$fks = DB::connection('custom')->select(
"SELECT constraint_name FROM information_schema.table_constraints WHERE table_name = ? AND constraint_type = 'FOREIGN KEY'",
['orders']
); Defensive patterns
Strategy: type-guard
Validate before calling
$grammar = Schema::getConnection()->getSchemaGrammar();
if (get_class($grammar) === \Illuminate\Database\Schema\Grammars\Grammar::class) {
throw new \DomainException('Connection uses the base Grammar; cannot list foreign keys.');
} Type guard
function supportsCompileForeignKeys(\Illuminate\Database\Schema\Grammars\Grammar $grammar): bool
{
return (new \ReflectionMethod($grammar, 'compileForeignKeys'))
->getDeclaringClass()->getName() !== \Illuminate\Database\Schema\Grammars\Grammar::class;
} Try / catch
try {
$fks = Schema::getForeignKeys('orders');
} catch (\RuntimeException $e) {
if (str_contains($e->getMessage(), 'retrieving foreign keys')) {
$fks = DB::select("SELECT * FROM information_schema.table_constraints WHERE table_name = ? AND constraint_type = 'FOREIGN KEY'", ['orders']);
} else {
throw $e;
}
} Prevention
- Bind a real grammar in custom connections; never ship the base Grammar.
- Implement compileForeignKeys when authoring a new grammar.
- In admin tooling, gate foreign-key introspection on the grammar class.
When it happens
Trigger: Schema::getForeignKeys($table) on a connection whose SchemaGrammar is the base Grammar (custom driver not implementing the method).
Common situations: Custom/community driver whose grammar was never filled in; an introspection/admin tool that calls getForeignKeys on every configured connection.
Related errors
- This database driver does not support dropping foreign keys.
- The database driver in use does not support vector indexes.
- This database driver does not support fulltext index…
- This database driver does not support fulltext index…
- This database driver does not support modifying columns.
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/3633cb68e9e4ba63.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Database/Schema/Grammars/Grammar.php:182
* @throws \RuntimeException
*/
public function compileVectorIndex(Blueprint $blueprint, Fluent $command)
{
throw new RuntimeException('The database driver in use does not support vector indexes.');
}
/**
* Compile the query to determine the foreign keys.
*
* @param string|null $schema
* @param string $table
* @return string
*
* @throws \RuntimeException
*/
public function compileForeignKeys($schema, $table)
{
throw new RuntimeException('This database driver does not support retrieving foreign keys.');
}
/**
* Compile a rename column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return list<string>|string
*/
public function compileRenameColumn(Blueprint $blueprint, Fluent $command)
{
return sprintf('alter table %s rename column %s to %s',
$this->wrapTable($blueprint),
$this->wrap($command->from),
$this->wrap($command->to)
);
}
View on GitHub (pinned to e0f6eb3518)