{
  "id": "android/sqliteconstraintexception-unique-constraint",
  "signature": "android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: users.email (code 1555)",
  "signature_zh": "android.database.sqlite.SQLiteConstraintException: 唯一约束失败：users.email (代码 1555)",
  "regex": "android\\.database\\.sqlite\\.SQLiteConstraintException: UNIQUE constraint failed: .*",
  "domain": "android",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "An INSERT or UPDATE operation attempted to set a value on a column with a UNIQUE constraint that already exists in the table.",
  "root_cause_type": "generic",
  "root_cause_zh": "INSERT 或 UPDATE 操作尝试在具有 UNIQUE 约束的列上设置一个表中已存在的值。",
  "versions": [
    {
      "version": "SQLite 3.42",
      "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 13 (API 33)",
      "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": "",
      "why_fails": "Clearing app cache does not affect the database, so the error persists.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding a try-catch around the INSERT without handling the duplicate (e.g., ignoring the error) may cause data loss or silent failures.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disabling the unique constraint via ALTER TABLE may break data integrity and cause other bugs.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use INSERT OR REPLACE or INSERT OR IGNORE in your SQL statement. Example: ContentValues values = new ContentValues(); values.put(\"email\", \"test@example.com\"); db.insertWithOnConflict(\"users\", null, values, SQLiteDatabase.CONFLICT_REPLACE);",
      "success_rate": 0.9,
      "how": "Use INSERT OR REPLACE or INSERT OR IGNORE in your SQL statement. Example: ContentValues values = new ContentValues(); values.put(\"email\", \"test@example.com\"); db.insertWithOnConflict(\"users\", null, values, SQLiteDatabase.CONFLICT_REPLACE);",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check for existing data before inserting: if (db.rawQuery(\"SELECT 1 FROM users WHERE email = ?\", new String[]{email}).getCount() == 0) { db.insert(...); }",
      "success_rate": 0.85,
      "how": "Check for existing data before inserting: if (db.rawQuery(\"SELECT 1 FROM users WHERE email = ?\", new String[]{email}).getCount() == 0) { db.insert(...); }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use Room's @Insert(onConflict = OnConflictStrategy.REPLACE) annotation to handle duplicate entries automatically.",
      "success_rate": 0.95,
      "how": "Use Room's @Insert(onConflict = OnConflictStrategy.REPLACE) annotation to handle duplicate entries automatically.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use INSERT OR REPLACE or INSERT OR IGNORE in your SQL statement. Example: ContentValues values = new ContentValues(); values.put(\"email\", \"test@example.com\"); db.insertWithOnConflict(\"users\", null, values, SQLiteDatabase.CONFLICT_REPLACE);",
    "Check for existing data before inserting: if (db.rawQuery(\"SELECT 1 FROM users WHERE email = ?\", new String[]{email}).getCount() == 0) { db.insert(...); }",
    "Use Room's @Insert(onConflict = OnConflictStrategy.REPLACE) annotation to handle duplicate entries automatically."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://developer.android.com/reference/android/database/sqlite/SQLiteConstraintException",
  "official_doc_section": null,
  "error_code": "1555",
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-04-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}