{"record":{"id":"9f2501ef34b33860","repo":"spring-projects/spring-ai","slug":"table-does-not-exist-in-schema","errorCode":null,"errorMessage":"Table  does not exist in schema ","messagePattern":"Table  does not exist in schema ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorSchemaValidator.java","lineNumber":98,"sourceCode":"\t}\n\n\tvoid validateNames(String schemaName, String tableName) {\n\t\tif (!isValidNameForDatabaseObject(schemaName)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Schema name should only contain alphanumeric characters and underscores\");\n\t\t}\n\t\tif (!isValidNameForDatabaseObject(tableName)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Table name should only contain alphanumeric characters and underscores\");\n\t\t}\n\t}\n\n\tvoid validateTableSchema(String schemaName, String tableName, int dimensions) {\n\n\t\tvalidateNames(schemaName, tableName);\n\n\t\tif (!isTableExists(schemaName, tableName)) {\n\t\t\tthrow new IllegalStateException(\"Table \" + tableName + \" does not exist in schema \" + schemaName);\n\t\t}\n\n\t\ttry {\n\t\t\tif (logger.isInfoEnabled()) {\n\t\t\t\tlogger.info(\"Validating PGVectorStore schema for table: \" + tableName + \" in schema: \" + schemaName);\n\t\t\t}\n\n\t\t\tList<String> expectedColumns = new ArrayList<>();\n\t\t\texpectedColumns.add(\"id\");\n\t\t\texpectedColumns.add(\"content\");\n\t\t\texpectedColumns.add(\"metadata\");\n\t\t\texpectedColumns.add(\"embedding\");\n\n\t\t\t// Query to check if the table exists with the required fields and types\n\t\t\t// Include the schema name in the query to target the correct table\n\t\t\tString query = \"SELECT column_name, data_type FROM information_schema.columns \"\n\t\t\t\t\t+ \"WHERE table_schema = ? AND table_name = ?\";\n\t\t\tList<Map<String, @Nullable Object>> columns = this.jdbcTemplate.queryForList(query,","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorSchemaValidator.java#L80-L116","documentation":"validateTableSchema checks information_schema/pg_catalog for the configured table and throws IllegalStateException when the table does not exist in the configured schema. This happens during store initialization when schema validation is enabled and create-if-missing is off.","triggerScenarios":"PgVectorStore initialized with schema validation (validateTableSchema) while the target table was never created — e.g. wrong table name, wrong schema (search_path), or initializeSchema=false against an empty database.","commonSituations":"Fresh environment/database where DDL was never run; initializeSchema disabled but the table expected to pre-exist; connecting to the wrong database or schema; typo in schema-name/table-name properties.","solutions":["Enable schema initialization: PgVectorStore.builder(...).initializeSchema(true) or set spring.ai.vectorstore.pgvector.initialize-schema=true.","Run the vector_store DDL manually in the configured schema.","Verify schema and table names match the actual PostgreSQL objects (SELECT from information_schema.tables).","Confirm the JDBC connection points at the intended database."],"exampleFix":"// before\nPgVectorStore.builder(jdbcTemplate, embeddingModel).initializeSchema(false).build();\n// after\nPgVectorStore.builder(jdbcTemplate, embeddingModel).initializeSchema(true).build();","handlingStrategy":"validation","validationCode":"Integer n = jdbcTemplate.queryForObject(\n    \"SELECT count(*) FROM information_schema.tables WHERE table_schema=? AND table_name=?\",\n    Integer.class, schemaName, tableName);\nif (n == null || n == 0) {\n    throw new IllegalStateException(\"Run DDL or set initializeSchema=true first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    vectorStore.similaritySearch(request);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"does not exist in schema\")) {\n        // run DDL or rebuild store with initializeSchema(true)\n    } else { throw e; }\n}","preventionTips":["Enable initializeSchema=true in fresh environments.","Apply vector_store DDL as a Flyway/Liquibase migration.","Double-check schema-name and table-name config against the actual database."],"tags":["pgvector","schema-validation","database"],"backgroundTag":"entity-not-found","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}