{"record":{"id":"7b4dea1d575f7050","repo":"clockworklabs/SpacetimeDB","slug":"original-error-multiple-primary-keys-detected-in","errorCode":null,"errorMessage":"Original error: Multiple primary keys detected in table '%s'\n\n","messagePattern":"Original error: Multiple primary keys detected in table '(.+?)'\n\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bindings-cpp/src/internal/Module.cpp","lineNumber":263,"sourceCode":"        // Create the error type name\n        std::string error_type_name = \"ERROR_MULTIPLE_PRIMARY_KEYS_\" + g_multiple_primary_key_table_name;\n        \n        // Add a single named type export that points to a non-existent typespace index\n        // This will cause SpacetimeDB to error when it tries to resolve the type\n        RawTypeDefV10 error_type;\n        error_type.source_name.scope = {};\n        error_type.source_name.source_name = error_type_name;\n        error_type.ty = 999999; // Invalid typespace index - will cause an error\n        error_type.custom_ordering = false;\n        \n        getV10Builder().GetTypeDefs().push_back(error_type);\n        \n        // Don't add anything to the typespace - this ensures the reference is invalid\n        // The server will fail with an error message that includes our error type name\n        \n        // Also log to stderr for debugging\n        fprintf(stderr, \"\\n[CONSTRAINT ERROR] Module cleared and replaced with error type: %s\\n\", error_type_name.c_str());\n        fprintf(stderr, \"Original error: Multiple primary keys detected in table '%s'\\n\\n\", g_multiple_primary_key_table_name.c_str());\n        fflush(stderr);\n        \n        return; // Exit early, don't check type registration errors\n    }\n\n    if (g_constraint_registration_error) {\n        getV10Builder().Clear();\n\n        std::string error_type_name = \"ERROR_CONSTRAINT_REGISTRATION_\" + g_constraint_registration_error_code;\n        for (char& c : error_type_name) {\n            if (!std::isalnum(c) && c != '_') {\n                c = '_';\n            }\n        }\n\n        RawTypeDefV10 error_type;\n        error_type.source_name.scope = {};\n        error_type.source_name.source_name = error_type_name;","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-cpp/src/internal/Module.cpp#L245-L281","documentation":"Detail line of the '[CONSTRAINT ERROR]' banner (error 666) that restates the root cause: multiple primary keys were detected in the named table (g_multiple_primary_key_table_name). It exists so the module-side stderr log carries the table name, since the server only sees the opaque ERROR_MULTIPLE_PRIMARY_KEYS_<table> error type.","triggerScenarios":"Emitted together with error 666 whenever __preinit__99_validate_types finds g_multiple_primary_key_error set; the table named here is the one carrying two or more primary-key constraints.","commonSituations":"Same as error 661/666 - duplicated or composite primary-key macros on one table struct.","solutions":["Open the table named on this line and keep a single FIELD_PrimaryKey/FIELD_PrimaryKeyAutoInc macro","Convert the surplus primary-key column to FIELD_Unique or part of a multi-column index","Republish and confirm the ERROR_MULTIPLE_PRIMARY_KEYS_* type no longer appears in the module description"],"exampleFix":"// before\nFIELD_PrimaryKey(Session, id);\nFIELD_PrimaryKey(Session, token);\n\n// after\nFIELD_PrimaryKey(Session, id);\nFIELD_Unique(Session, token);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Search all translation units for primary-key macros on the table named here","Convert surplus keys to FIELD_Unique or multi-column indexes","Keep constraints and struct in one place for reviewability"],"tags":["spacetimedb","cpp","schema","primary-key","diagnostics"],"backgroundTag":"multiple-primary-keys","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}