{"record":{"id":"6bc353b248330f51","repo":"pubkey/rxdb","slug":"sc39","errorCode":"SC39","errorMessage":"\n        RxDB Error-Code: ${message}.\n        Hint: Error messages are not included in RxDB core to reduce build size.\n        To show the full error messages and to ensure that you do not make any mistakes when using RxDB,\n        use the dev-mode plugin when you are in development mode: https://rxdb.info/dev-mode.html?console=error\n        \nFind out more about this error here: https://rxdb.info/errors.html?console=errors#SC39 \nStill stuck? Ask in the RxDB Discord: https://rxdb.info/chat \n","messagePattern":"\n        RxDB Error-Code: (.+?)\\.\n        Hint: Error messages are not included in RxDB core to reduce build size\\.\n        To show the full error messages and to ensure that you do not make any mistakes when using RxDB,\n        use the dev-mode plugin when you are in development mode: https://rxdb\\.info/dev-mode\\.html\\?console=error\n        \nFind out more about this error here: https://rxdb\\.info/errors\\.html\\?console=errors#SC39 \nStill stuck\\? Ask in the RxDB Discord: https://rxdb\\.info/chat \n","errorType":"error_code","errorClass":"RxError","httpStatus":null,"severity":"error","filePath":"src/rx-schema.ts","lineNumber":54,"sourceCode":"    public readonly primaryPath: StringKeys<RxDocumentData<RxDocType>>;\n    public finalFields: string[];\n\n    constructor(\n        public readonly jsonSchema: RxJsonSchema<RxDocumentData<RxDocType>>,\n        public readonly hashFunction: HashFunction\n    ) {\n        this.indexes = getIndexes(this.jsonSchema);\n\n        // primary is always required\n        this.primaryPath = getPrimaryFieldOfPrimaryKey(this.jsonSchema.primaryKey);\n\n        /**\n         * Many people accidentally put in wrong schema state\n         * without the dev-mode plugin, so we need this check here\n         * even in non-dev-mode.\n         */\n        if (!jsonSchema.properties[this.primaryPath].maxLength) {\n            throw newRxError('SC39', { schema: jsonSchema });\n        }\n\n        this.finalFields = getFinalFields(this.jsonSchema);\n    }\n\n    public get version(): number {\n        return this.jsonSchema.version;\n    }\n\n    public get defaultValues(): { [P in keyof RxDocType]: RxDocType[P] } {\n        const values = {} as { [P in keyof RxDocType]: RxDocType[P] };\n        Object\n            .entries(this.jsonSchema.properties)\n            .filter(([, v]) => Object.prototype.hasOwnProperty.call(v, 'default'))\n            .forEach(([k, v]) => (values as any)[k] = (v as any).default);\n        return overwriteGetterForCaching(\n            this,\n            'defaultValues',","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-schema.ts#L36-L72","documentation":"SC39 is thrown in the RxSchema constructor when the schema's primary key property has no maxLength set. RxDB requires string primary keys to declare a maximum length so storage backends can size keys and validate document ids. This check runs even without the dev-mode plugin because invalid schemas are such a common mistake.","triggerScenarios":"Calling createRxDatabase().addCollections() (or constructing RxSchema directly) with a JSON schema whose primaryKey is a string field that lacks maxLength in its property definition, e.g. { properties: { id: { type: 'string' } }, primaryKey: 'id' } with no maxLength: 100.","commonSituations":"Copy-pasting a schema and dropping the maxLength; switching from a numeric to a string primary key; following outdated tutorials or LLM-generated schemas that omit maxLength; upgrading RxDB where the check became stricter.","solutions":["Add maxLength to the primary key property in your schema, e.g. { id: { type: 'string', maxLength: 100 } }.","Use a string primary key with maxLength: 100 as recommended in the RxDB quickstart.","Validate your schema with the dev-mode plugin to catch other schema mistakes at startup.","For composite primary keys, ensure the referenced key fields are string properties with maxLength set."],"exampleFix":"// before\nconst schema = {\n  title: 'hero',\n  version: 0,\n  primaryKey: 'id',\n  properties: { id: { type: 'string' } }\n};\n// after\nconst schema = {\n  title: 'hero',\n  version: 0,\n  primaryKey: 'id',\n  properties: { id: { type: 'string', maxLength: 100 } }\n};","handlingStrategy":"validation","validationCode":"function primaryKeyHasMaxLength(schema: RxJsonSchema<any>): boolean {\n  const primaryPath = typeof schema.primaryKey === 'string'\n    ? schema.primaryKey\n    : (schema.primaryKey as any).key;\n  const prop = schema.properties[primaryPath];\n  return !!prop && prop.type === 'string' && typeof prop.maxLength === 'number' && prop.maxLength > 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await db.addCollections({ heroes: { schema: mySchema } });\n} catch (err: any) {\n  if (err.code === 'SC39') {\n    console.error('Primary key property needs maxLength, fix the schema', err.parameters?.schema);\n  } else throw err;\n}","preventionTips":["Always define string primary keys as { type: 'string', maxLength: 100 }.","Copy schemas from the current official quickstart, not outdated tutorials.","Run the dev-mode plugin so schema mistakes surface at startup with full messages.","For composite keys, give every field referenced by primaryKey.fields a maxLength."],"tags":["schema","primary-key","maxlength","configuration"],"backgroundTag":"invalid-rx-schema","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}