{"record":{"id":"748dcd9bcf63a34c","repo":"spring-projects/spring-ai","slug":"missing-fields","errorCode":null,"errorMessage":"Missing fields ","messagePattern":"Missing fields ","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":138,"sourceCode":"\t\t\t\tthrow new IllegalStateException(\"Error while validating table schema, Table \" + tableName\n\t\t\t\t\t\t+ \" does not exist in schema \" + schemaName);\n\t\t\t}\n\n\t\t\t// Check each column against expected fields\n\t\t\tList<String> availableColumns = new ArrayList<>();\n\t\t\tfor (Map<String, @Nullable Object> column : columns) {\n\t\t\t\tString columnName = (String) column.get(\"column_name\");\n\t\t\t\tavailableColumns.add(columnName);\n\n\t\t\t}\n\n\t\t\texpectedColumns.removeAll(availableColumns);\n\n\t\t\tif (expectedColumns.isEmpty()) {\n\t\t\t\tlogger.info(\"PG VectorStore schema validation successful\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalStateException(\"Missing fields \" + expectedColumns);\n\t\t\t}\n\n\t\t\t// Query the actual dimensions\n\t\t\tquery = \"\"\"\n\t\t\t\t\tSELECT\n\t\t\t\t\t\ta.atttypmod\n\t\t\t\t\tFROM\n\t\t\t\t\t\tpg_attribute a\n\t\t\t\t\tJOIN\n\t\t\t\t\t\tpg_class c ON a.attrelid = c.oid\n\t\t\t\t\tJOIN\n\t\t\t\t\t\tpg_namespace n ON c.relnamespace = n.oid\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tn.nspname = ?\n\t\t\t\t\t\tAND c.relname = ?\n\t\t\t\t\t\tAND a.attname = ?\n\t\t\t\t\t\tAND a.attnum > 0\n\t\t\t\t\t\tAND NOT a.attisdropped","sourceCodeStart":120,"sourceCodeEnd":156,"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#L120-L156","documentation":"validateTableSchema compares the table's actual columns against the expected vector_store column set (id, content, metadata, embedding, and related columns). If any expected columns are absent from the table, it throws IllegalStateException listing the missing fields. This catches tables created by an older version of the library or hand-made with a different layout.","triggerScenarios":"Pointing PgVectorStore schema validation at a table created by an earlier Spring AI version or by a custom DDL that lacks one of the required columns (e.g. missing metadata or index columns).","commonSituations":"Upgrading spring-ai after the vector_store schema changed; a table created by another framework with a similar name; partially applied migrations.","solutions":["Drop/recreate or ALTER the table to match the current expected schema, ideally by enabling initializeSchema=true against a fresh table.","Add the missing columns via ALTER TABLE vector_store ADD COLUMN ... per the listed fields.","Compare your DDL against the CREATE_VECTOR_STORE_SQL in PgVectorStore for your library version.","Pin the Spring AI version so schema and code stay consistent."],"exampleFix":"// before\nCREATE TABLE vector_store (id uuid PRIMARY KEY, content text);\n// after\nALTER TABLE vector_store ADD COLUMN metadata json;\nALTER TABLE vector_store ADD COLUMN embedding vector(1536);","handlingStrategy":"validation","validationCode":"Set<String> expected = Set.of(\"id\", \"content\", \"metadata\", \"embedding\");\nSet<String> actual = jdbcTemplate.queryForList(\n    \"SELECT column_name FROM information_schema.columns WHERE table_schema=? AND table_name=?\",\n    String.class, schemaName, tableName).stream().collect(Collectors.toSet());\nSet<String> missing = new HashSet<>(expected); missing.removeAll(actual);\nif (!missing.isEmpty()) {\n    throw new IllegalStateException(\"Missing columns: \" + missing);\n}","typeGuard":null,"tryCatchPattern":"try {\n    vectorStore.afterPropertiesSet();\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Missing fields\")) {\n        // ALTER TABLE to add missing columns or recreate\n    } else { throw e; }\n}","preventionTips":["Recreate the table when upgrading Spring AI versions that changed the schema.","Keep DDL in versioned migrations aligned with the library version.","Run schema validation in CI against a test database."],"tags":["pgvector","schema-validation","migration"],"backgroundTag":"schema-validation-failed","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"}