{"record":{"id":"c0abec9600901438","repo":"invoke-ai/InvokeAI","slug":"problem-bootstrapping-applied-migrations-e","errorCode":null,"errorMessage":"Problem bootstrapping applied migrations: {e}","messagePattern":"Problem bootstrapping applied migrations: (.+?)","errorType":"exception","errorClass":"MigrationError","httpStatus":null,"severity":"critical","filePath":"invokeai/app/services/shared/sqlite_migrator/sqlite_migrator_impl.py","lineNumber":208,"sourceCode":"                    (legacy_version,),\n                )\n                legacy_row = cursor.fetchone()\n                if legacy_row is not None and legacy_row[0] != migration_id:\n                    cursor.connection.rollback()\n                    raise MigrationError(\n                        \"Database contains inconsistent applied migration state: \"\n                        f\"legacy version {legacy_version} is recorded for {legacy_row[0]}, expected {migration_id}\"\n                    )\n                cursor.execute(\n                    \"INSERT OR IGNORE INTO applied_migrations (migration_id, legacy_version) VALUES (?, ?);\",\n                    (migration_id, legacy_version),\n                )\n            cursor.connection.commit()\n        except sqlite3.Error as e:\n            msg = f\"Problem bootstrapping applied migrations: {e}\"\n            self._logger.error(msg)\n            cursor.connection.rollback()\n            raise MigrationError(msg) from e\n\n    def _validate_existing_applied_migrations(self, cursor: sqlite3.Cursor) -> None:\n        \"\"\"Validates existing applied migration IDs before creating or mutating migrator metadata.\"\"\"\n        applied_migration_ids = self._get_applied_migration_ids(cursor=cursor)\n        if len(applied_migration_ids) == 0:\n            return\n        known_migration_ids = set(self._migration_set.migrations_by_id)\n        unknown_applied_ids = applied_migration_ids - known_migration_ids\n        if unknown_applied_ids:\n            unknown_ids = \", \".join(sorted(unknown_applied_ids))\n            raise MigrationError(f\"Database contains unknown applied migration IDs: {unknown_ids}\")\n\n    def _validate_existing_legacy_migrations(self, cursor: sqlite3.Cursor) -> None:\n        \"\"\"Validates existing legacy migration versions before creating applied migration metadata.\"\"\"\n        try:\n            cursor.execute(\"SELECT version FROM migrations WHERE version > 0 ORDER BY version;\")\n        except sqlite3.OperationalError as e:\n            if \"no such table\" in str(e):","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/shared/sqlite_migrator/sqlite_migrator_impl.py#L190-L226","documentation":"Wrapper guard: any sqlite3.Error raised while bootstrapping applied migrations from legacy versions is logged, the transaction is rolled back, and re-raised as a MigrationError with the underlying message chained as the cause. It converts low-level SQLite failures into the migrator's error type.","triggerScenarios":"sqlite3 errors during bootstrap — locked database, disk I/O error, malformed schema (missing applied_migrations or legacy tables), permission problems on the DB file — inside _bootstrap_applied_migrations_from_legacy_versions.","commonSituations":"DB file locked by another running InvokeAI instance; read-only filesystem or insufficient permissions; corrupted SQLite file; schema missing expected tables.","solutions":["Read the chained sqlite3 error message (the cause) to identify the root problem","Ensure no other process holds the DB and file permissions allow writes","Restore or repair the DB (e.g. sqlite3 .recover) if corruption is indicated","Back up the DB before retrying migrations"],"exampleFix":"# before: db locked by another instance / read-only file\n# after: stop other instances and ensure write access\nfuser /data/invokeai/invokeai.db\nchmod u+w /data/invokeai/invokeai.db\ninvokeai-web --root /data/invokeai","handlingStrategy":"try-catch","validationCode":"import os, sqlite3\nassert os.access(db_path, os.W_OK), f\"no write access to {db_path}\"\nconn = sqlite3.connect(db_path)\nconn.execute(\"PRAGMA integrity_check\")\nconn.execute(\"BEGIN IMMEDIATE; conn_rollback\") if False else None","typeGuard":null,"tryCatchPattern":"try:\n    services.run_migrations()\nexcept MigrationError as e:\n    if \"Problem bootstrapping applied migrations\" in str(e):\n        logger.critical(\"SQLite-level bootstrap failure: %s\", e.__cause__)\n        raise\n    raise","preventionTips":["Ensure the DB file and directory are writable by the app user","Stop other InvokeAI instances before migrating (avoid SQLITE_BUSY)","Periodically run PRAGMA integrity_check on the database","Always back up the DB before migrations"],"tags":["database","sqlite","migrations","bootstrap"],"backgroundTag":"sqlite-migration-failure","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}