{"record":{"id":"1ff0b2246e9514ff","repo":"pubkey/rxdb","slug":"db6","errorCode":"DB6","errorMessage":"RxDB Error-Code: DB6. Hint: Error messages are not included in RxDB core to reduce build size. To show the full error messages and to ensure that you do not make any mistakes when using RxDB, use the dev-mode plugin when you are in development mode: https://rxdb.info/dev-mode.html?console=error","messagePattern":"RxDB Error-Code: DB6\\. Hint: Error messages are not included in RxDB core to reduce build size\\. To show the full error messages and to ensure that you do not make any mistakes when using RxDB, use the dev-mode plugin when you are in development mode: https://rxdb\\.info/dev-mode\\.html\\?console=error","errorType":"error_code","errorClass":"RxError","httpStatus":null,"severity":"error","filePath":"src/rx-database.ts","lineNumber":464,"sourceCode":"                    'rx-database-add-collection'\n                ),\n                ensureNoStartupErrors(this)\n            ]);\n\n            await Promise.all(\n                putDocsResult.error.map(async (error) => {\n                    if (error.status !== 409) {\n                        throw newRxError('DB12', {\n                            database: this.name,\n                            writeError: error\n                        });\n                    }\n                    const docInDb: RxDocumentData<InternalStoreCollectionDocType> = ensureNotFalsy(error.documentInDb);\n                    const collectionName = docInDb.data.name;\n                    const schema = (schemas as any)[collectionName];\n                    // collection already exists but has different schema\n                    if (docInDb.data.schemaHash !== await schema.hash) {\n                        throw newRxError('DB6', {\n                            database: this.name,\n                            collection: collectionName,\n                            previousSchemaHash: docInDb.data.schemaHash,\n                            schemaHash: await schema.hash,\n                            previousSchema: docInDb.data.schema,\n                            schema: ensureNotFalsy((jsonSchemas as any)[collectionName])\n                        });\n                    }\n                })\n            );\n        } catch (err) {\n            /**\n             * Close any pre-created storage instances on error.\n             * Some instances might have failed to create (rejected promise),\n             * so we catch and ignore errors during cleanup.\n             */\n            await Promise.all(\n                Object.values(collectionStorageInstancePromises).map(","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-database.ts#L446-L482","documentation":"DB6 is thrown when a collection already exists in the internal store but with a different schema hash than the schema you are now passing to addCollections(). RxDB stores a hash of each collection's schema; re-creating a collection with a changed schema is not allowed because existing documents would not match. You must either keep the schema identical or create a schema migration / a new collection.","triggerScenarios":"Calling addCollections() for a collection name that already exists on disk while the RxJsonSchema has been modified (added/removed/changed fields, changed version without migration strategy), so the computed schema hash differs from the stored one.","commonSituations":"Editing a schema during development while the old collection data persists in IndexedDB/LocalStorage; renaming or retyping fields; bumping schema version without providing a migration strategy; sharing one database between app versions with divergent schemas.","solutions":["Revert the schema to match the stored one, or increment the schema version and add a migrationStrategies entry for the new version.","During development only, delete the persisted database (e.g. clear IndexedDB or call db.remove()) so the new schema is created fresh.","Use RxDB's migration plugin: addCollections with the new versioned schema plus migrationStrategies so old documents are migrated.","Do not mutate an existing collection's schema in place; design schema changes as version +1 with a migration."],"exampleFix":"// before\nconst heroSchema = { title: 'hero', version: 0, properties: { name: { type: 'string' }, age: { type: 'number' } } };\nawait db.addCollections({ heroes: { schema: heroSchema } });\n// after\nconst heroSchema = { title: 'hero', version: 1, properties: { name: { type: 'string' }, age: { type: 'number' } }, required: ['name'] };\nawait db.addCollections({\n  heroes: {\n    schema: heroSchema,\n    migrationStrategies: {\n      0: (oldDoc) => oldDoc\n    }\n  }\n});","handlingStrategy":"validation","validationCode":"const stored = await getStoredSchemaHash(db, 'heroes');\nconst current = await createRxSchema(heroSchema, db.hashFunction).hash;\nif (stored && stored !== current) {\n  heroSchema.version += 1; // and add migrationStrategies\n}","typeGuard":"function schemasEqual(a: RxJsonSchema<any>, b: RxJsonSchema<any>): boolean {\n  return JSON.stringify(normalizeSchema(a)) === JSON.stringify(normalizeSchema(b));\n}","tryCatchPattern":"try {\n  await db.addCollections(defs);\n} catch (err) {\n  if (isRxError(err) && err.code === 'DB6') {\n    console.error('Schema changed for existing collection; bump version and add migrationStrategies', err.parameters?.collection);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Treat schemas as immutable once shipped: every change is version+1 plus a migration strategy.","In development, clear persisted storage (IndexedDB) when iterating on schemas, or call db.remove().","Keep schema definitions in a versioned module so old versions remain available for migrations.","Test schema upgrades against a copy of production data before release."],"tags":["schema-mismatch","schema-hash","migration"],"backgroundTag":"schema-version-mismatch","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}