{"id":"702263771570408f","repo":"laravel/framework","slug":"database-connection-name-not-configured","errorCode":null,"errorMessage":"Database connection [{$name}] not configured.","messagePattern":"Database connection \\[(.+?)\\] not configured\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/DatabaseManager.php","lineNumber":226,"sourceCode":"        return $this->factory->make($config, $name);\n    }\n\n    /**\n     * Get the configuration for a connection.\n     *\n     * @param  string  $name\n     * @return array\n     *\n     * @throws \\InvalidArgumentException\n     */\n    protected function configuration($name)\n    {\n        $connections = $this->app['config']['database.connections'];\n\n        $config = $this->dynamicConnectionConfigurations[$name] ?? Arr::get($connections, $name);\n\n        if (is_null($config)) {\n            throw new InvalidArgumentException(\"Database connection [{$name}] not configured.\");\n        }\n\n        return (new ConfigurationUrlParser)\n            ->parseConfiguration($config);\n    }\n\n    /**\n     * Prepare the database connection instance.\n     *\n     * @param  \\Illuminate\\Database\\Connection  $connection\n     * @param  string  $type\n     * @return \\Illuminate\\Database\\Connection\n     */\n    protected function configure(Connection $connection, $type)\n    {\n        $connection = $this->setPdoForType($connection, $type)->setReadWriteType($type);\n\n        // First we'll set the fetch mode and a few other dependencies of the database","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/DatabaseManager.php#L208-L244","documentation":"Thrown by DatabaseManager::configuration() when there is no config entry at database.connections.{name} (and no dynamic connection config registered for that name). It guards every connection resolution against an undefined name.","triggerScenarios":"Calling DB::connection('reporting') when 'reporting' is not a key in database.connections; using an EnvEnum/string that doesn't map to a configured connection; passing a typo'd name from request input.","commonSituations":"DB_CONNECTION set to an undefined name; multi-tenant code resolving a tenant connection that wasn't bootstrapped; default connection name changed but config not updated; config:cache run before the connection was added.","solutions":["Add the missing connection to config/database.php under database.connections.{name}.","Verify the name passed to DB::connection() matches a configured key exactly (case, hyphens).","Run php artisan config:clear if you recently added the connection.","If the name is dynamic, register it via DatabaseManager::addConnection($name, $config) before resolving."],"exampleFix":"// before\n$conn = DB::connection('reporting'); // not configured -> throws\n\n// after\n// config/database.php\n'connections' => [\n    'reporting' => ['driver'=>'mysql','host'=>env('DB_REPORTING_HOST'), ...],\n],\nphp artisan config:clear\nDB::connection('reporting');","handlingStrategy":"validation","validationCode":"if (empty(config('database.connections.'.$name))) {\n    throw new \\RuntimeException(\"Database connection [$name] is not configured.\");\n}","typeGuard":"function connectionConfigured(string $name): bool {\n    return ! empty(config('database.connections.'.$name));\n}","tryCatchPattern":null,"preventionTips":["Whitelist dynamic connection names against array_keys(config('database.connections')).","Use DatabaseManager::addConnection($name, $config) for runtime connections.","Run config:clear after adding connections.","Add a CI config-validation step asserting the default connection exists."],"tags":["configuration","connection","multi-tenant"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}