{"record":{"id":"8211efdd860b3dd9","repo":"clockworklabs/SpacetimeDB","slug":"error-field-s-not-found-in-table-s","errorCode":null,"errorMessage":"ERROR: Field '%s' not found in table '%s'\n","messagePattern":"ERROR: Field '(.+?)' not found in table '(.+?)'\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bindings-cpp/include/spacetimedb/internal/v9_builder.h","lineNumber":465,"sourceCode":"        fprintf(stderr, \"ERROR: No field descriptors found for table %s\\n\", table_name.c_str());\n        return;\n    }\n    \n    const auto& field_descs = it->second.fields;\n    uint16_t field_idx = 0;\n    bool field_found = false;\n    \n    // Find the field index\n    for (const auto& field_desc : field_descs) {\n        if (field_desc.name == field_name) {\n            field_found = true;\n            break;\n        }\n        field_idx++;\n    }\n    \n    if (!field_found) {\n        fprintf(stderr, \"ERROR: Field '%s' not found in table '%s'\\n\", \n                field_name.c_str(), table_name.c_str());\n        return;\n    }\n    \n    // Add constraint based on type\n    int constraint_bits = static_cast<int>(constraint);\n    \n    // Check for PrimaryKey (has specific bit 0b1000)\n    if (constraint_bits & 0b1000) {  // PrimaryKey-specific bit\n        // Validate that there isn't already a primary key\n        if (!table->primary_key.empty()) {\n            // Set the error flag instead of crashing - this will be handled by preinit_99\n            SetMultiplePrimaryKeyError(table_name);\n            return; // Exit early to avoid adding the conflicting primary key\n        }\n        table->primary_key.push_back(field_idx);\n        \n        // PrimaryKey implies Unique constraint and index","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-cpp/include/spacetimedb/internal/v9_builder.h#L447-L483","documentation":"AddFieldConstraint resolved the table and its field descriptors, but the requested field_name does not match any field_desc.name in the descriptor list, so it cannot compute the column index and drops the constraint. The comparison is exact and case-sensitive against the names produced by the row type's field registration.","triggerScenarios":"Renaming a struct member without updating the constraint macro's field string; passing the database column name when the descriptor uses the C++ member name (or vice versa); whitespace/typo differences in the quoted field name; constraining a field that exists only in a different type than T.","commonSituations":"Schema refactors where the member is renamed (e.g. userId -> user_id) but constraint annotations keep the old string; macro-generated field names that differ from expectations; copy-paste of constraint macros between similar tables.","solutions":["Verify the field string in the constraint macro exactly matches the C++ member name declared in the row struct (case-sensitive)","If the member was renamed, update every constraint/index/default annotation that references it","Confirm the field is declared in the same struct T that the macro uses, not in a base class or sibling type","Republish and describe the table to confirm the constraint took effect"],"exampleFix":"// before\nstruct User { uint64_t user_id; std::string name; };\nST_UNIQUE(user, id);   // 'id' not among descriptors ('user_id','name')\n// after\nstruct User { uint64_t user_id; std::string name; };\nST_UNIQUE(user, user_id);","handlingStrategy":"validation","validationCode":"// Check the field name exists among registered descriptors before annotating:\n// after static init, for row type T:\nSpacetimeDB::field_registrar<T>::register_fields();\nauto& descs = SpacetimeDB::get_table_descriptors();\n// verify a field named 'id' exists for typeid(T) before adding ST_UNIQUE(T,\"...\",\"id\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Single-source field name strings: generate or share constants between struct and annotations where possible","Rename fields and their annotations in the same commit","Add a schema-diff test comparing published constraints against expectations"],"tags":["spacetimedb","cpp","schema","unknown-field","constraint","rename"],"backgroundTag":"unknown-schema-field","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}