{"record":{"id":"6a99043e80d33ef2","repo":"immich-app/immich","slug":"migration-missing-1-was-already-applied-to-t","errorCode":null,"errorMessage":"Migration \"${missing[1]}\" was already applied to this database but is not in this version of Immich (${serverVersion}). This usually means the database was migrated by a newer version. Downgrades are not supported.","messagePattern":"Migration \"(.+?)\" was already applied to this database but is not in this version of Immich \\((.+?)\\)\\. This usually means the database was migrated by a newer version\\. Downgrades are not supported\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/src/repositories/database.repository.ts","lineNumber":390,"sourceCode":"    const migrator = this.createMigrator();\n\n    const { error, results } = await migrator.migrateToLatest();\n\n    for (const result of results ?? []) {\n      if (result.status === 'Success') {\n        this.logger.log(`Migration \"${result.migrationName}\" succeeded`);\n      } else if (result.status === 'Error') {\n        this.logger.warn(`Migration \"${result.migrationName}\" failed`);\n      }\n    }\n\n    if (error) {\n      this.logger.error(`Migrations failed: ${error}`);\n\n      const missing =\n        error instanceof Error ? error.message.match(/previously executed migration (.+) is missing/u) : null;\n      if (missing) {\n        throw new Error(\n          `Migration \"${missing[1]}\" was already applied to this database but is not in this version of Immich (${serverVersion}). ` +\n            `This usually means the database was migrated by a newer version. Downgrades are not supported.`,\n          { cause: error },\n        );\n      }\n\n      throw error;\n    }\n\n    this.logger.log('Finished running migrations');\n  }\n\n  async migrateFilePaths(sourceFolder: string, targetFolder: string): Promise<void> {\n    // remove trailing slashes\n    if (sourceFolder.endsWith('/')) {\n      sourceFolder = sourceFolder.slice(0, -1);\n    }\n","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/immich-app/immich/blob/199723261c6ffa897fec8ccdaea6359e39c37cc3/server/src/repositories/database.repository.ts#L372-L408","documentation":"During runMigrations, if Kysely migrator errors and the message matches 'previously executed migration <name> is missing', Immich rethrows a descriptive error. That Kysely error means a migration recorded as applied in the kysely_migrations table does not exist in the code migration set — i.e. the database was migrated by a newer Immich and you are now running an older one. Immich does not support downgrades.","triggerScenarios":"Rolling back to an older Immich version after a newer version already applied migrations to the database; restoring a DB backup taken on a newer server into an older server.","commonSituations":"Downgrading Immich after an upgrade; mixing versions in a HA setup; restoring production DB into an older test instance.","solutions":["Run the newer Immich version that contains the listed migration (forward-only — do not try to revert the DB).","If you must use the older version, restore the database from a backup made before the newer migrations were applied.","Align all instances pointing at the same DB to the same (newest) Immich version."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before starting an older server, check for unknown applied migrations\nconst { rows } = await sql`SELECT name FROM kysely_migrations`;\nconst known = new Set(await readLocalMigrationNames());\nconst unknown = rows.filter((r) => !known.has(r.name));\nif (unknown.length) throw new Error('DB has newer migrations; do not downgrade.');","typeGuard":null,"tryCatchPattern":"try {\n  await repo.runMigrations();\n} catch (e) {\n  if (/not in this version of Immich/.test((e as Error).message)) {\n    // upgrade Immich to the version that migrated the DB; do not roll back\n  } else throw e;\n}","preventionTips":["Treat Immich migrations as forward-only; never downgrade the server below the DB migration level.","Keep all instances on the same version when sharing a DB.","Before restoring a DB backup, ensure the target server version is >= the source."],"tags":["database","migration","kysely","versioning","downgrade","startup"],"backgroundTag":null,"analyzedSha":"199723261c6ffa897fec8ccdaea6359e39c37cc3","analyzedAt":"2026-08-12T04:54:27.085Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}