{"id":"b6bc5c33ac10dcff","repo":"laravel/framework","slug":"using-three-part-references-is-not-supported-you","errorCode":null,"errorMessage":"Using three-part references is not supported, you may use `Schema::connection('{$segments[0]}')` instead.","messagePattern":"Using three-part references is not supported, you may use `Schema::connection\\('(.+?)'\\)` instead\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Schema/Builder.php","lineNumber":757,"sourceCode":"    {\n        return $this->getCurrentSchemaListing()[0] ?? null;\n    }\n\n    /**\n     * Parse the given database object reference and extract the schema and table.\n     *\n     * @param  string  $reference\n     * @param  string|bool|null  $withDefaultSchema\n     * @return array{string|null, string}\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function parseSchemaAndTable($reference, $withDefaultSchema = null)\n    {\n        $segments = explode('.', $reference);\n\n        if (count($segments) > 2) {\n            throw new InvalidArgumentException(\n                \"Using three-part references is not supported, you may use `Schema::connection('{$segments[0]}')` instead.\"\n            );\n        }\n\n        $table = $segments[1] ?? $segments[0];\n\n        $schema = match (true) {\n            isset($segments[1]) => $segments[0],\n            is_string($withDefaultSchema) => $withDefaultSchema,\n            $withDefaultSchema => $this->getCurrentSchemaName(),\n            default => null,\n        };\n\n        return [$schema, $table];\n    }\n\n    /**\n     * Get the database connection instance.","sourceCodeStart":739,"sourceCodeEnd":775,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Schema/Builder.php#L739-L775","documentation":"Builder::parseSchemaAndTable() throws InvalidArgumentException when the supplied reference has more than two dot-separated segments (Builder.php:756). Laravel resolves only schema.table; a third segment implies database.schema.table, which the API refuses, pointing the caller to Schema::connection() for the database portion.","triggerScenarios":"Passing 'db_name.schema.table' (or any reference with 2+ dots) to any schema API that calls parseSchemaAndTable: getColumns(), getIndexes(), getForeignKeys(), hasTable(), table(), dropColumns(), etc. Common with SQL Server where three-part names are idiomatic.","commonSituations":"SQL Server users passing database.schema.table; cross-database references on Postgres; tooling that auto-qualifies names with the database name.","solutions":["Use Schema::connection('db_name')->... and pass only 'schema.table' (two segments).","Drop the database prefix from the string and configure it via the connection instead.","Strip extra segments before the call if the leading segment is the default DB."],"exampleFix":"// before\nSchema::getColumns('mydb.public.users');\n\n// after\nSchema::connection('mydb')->getColumns('public.users');","handlingStrategy":"validation","validationCode":"if (substr_count($reference, '.') > 1) {\n    [$db, $rest] = explode('.', $reference, 2);\n    Schema::connection($db)->getColumns($rest);\n} else {\n    Schema::getColumns($reference);\n}","typeGuard":"function isTwoPartReference(string $reference): bool\n{\n    return substr_count($reference, '.') <= 1;\n}","tryCatchPattern":"try {\n    Schema::getColumns($reference);\n} catch (\\InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'three-part references')) {\n        // split database segment into Schema::connection() and retry\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Pass only 'schema.table' (≤2 segments) to schema APIs.","Route the database segment via Schema::connection().","Validate dotted references from user/tooling input before calling schema methods."],"tags":["schema","database","sql-server","cross-database","argument-validation"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}