{
  "id": "android/room-migration-ambiguous-column-type",
  "signature": "android.database.sqlite.SQLiteException: Cannot read from cursor: column 'timestamp' has type TEXT but expected INTEGER (code 0)",
  "signature_zh": "android.database.sqlite.SQLiteException: 无法从游标读取: 列'timestamp'类型为TEXT但期望INTEGER（代码0）",
  "regex": "android\\.database\\.sqlite\\.SQLiteException: Cannot read from cursor: column '.*' has type .* but expected .* \\(code 0\\)",
  "domain": "android",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Room migration script altered the schema without converting existing data types, causing a mismatch between the expected SQLite affinity (INTEGER) and the actual stored type (TEXT) in the column.",
  "root_cause_type": "generic",
  "root_cause_zh": "Room迁移脚本更改了架构但未转换现有数据类型，导致预期SQLite亲和类型（INTEGER）与列中实际存储类型（TEXT）不匹配。",
  "versions": [
    {
      "version": "Room 2.6.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Android 12 (API 31)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Android 11 (API 30)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Room 2.5.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Delete app data and reinstall",
      "why_fails": "This only works for development but destroys user data in production. The underlying migration issue is not fixed.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Add fallbackToDestructiveMigration() to Room database builder",
      "why_fails": "This drops the entire database on migration failure, losing all user data. It's a nuclear option that doesn't fix the type mismatch.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Write a manual migration that converts TEXT to INTEGER using CAST. Example in migration: ALTER TABLE my_table ADD COLUMN timestamp_temp INTEGER; UPDATE my_table SET timestamp_temp = CAST(timestamp AS INTEGER); ALTER TABLE my_table DROP COLUMN timestamp; ALTER TABLE my_table RENAME COLUMN timestamp_temp TO timestamp;",
      "success_rate": 0.9,
      "how": "Write a manual migration that converts TEXT to INTEGER using CAST. Example in migration: ALTER TABLE my_table ADD COLUMN timestamp_temp INTEGER; UPDATE my_table SET timestamp_temp = CAST(timestamp AS INTEGER); ALTER TABLE my_table DROP COLUMN timestamp; ALTER TABLE my_table RENAME COLUMN timestamp_temp TO timestamp;",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use @TypeConverter to handle both types in the DAO. Example: @TypeConverter public static Long fromTimestamp(String value) { return value == null ? null : Long.parseLong(value); }",
      "success_rate": 0.85,
      "how": "Use @TypeConverter to handle both types in the DAO. Example: @TypeConverter public static Long fromTimestamp(String value) { return value == null ? null : Long.parseLong(value); }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Write a manual migration that converts TEXT to INTEGER using CAST. Example in migration: ALTER TABLE my_table ADD COLUMN timestamp_temp INTEGER; UPDATE my_table SET timestamp_temp = CAST(timestamp AS INTEGER); ALTER TABLE my_table DROP COLUMN timestamp; ALTER TABLE my_table RENAME COLUMN timestamp_temp TO timestamp;",
    "Use @TypeConverter to handle both types in the DAO. Example: @TypeConverter public static Long fromTimestamp(String value) { return value == null ? null : Long.parseLong(value); }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://developer.android.com/training/data-storage/room/migrating-databases",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.87,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}