{
  "id": "python/flask-sqlalchemy-commit-error",
  "signature": "sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: users.email",
  "signature_zh": "SQLAlchemy完整性错误：（sqlite3.完整性错误）唯一约束失败：users.email",
  "regex": "sqlalchemy\\.exc\\.IntegrityError:\\ \\(sqlite3\\.IntegrityError\\)\\ UNIQUE\\ constraint\\ failed:\\ users\\.email",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Attempt to insert a duplicate value into a column with a UNIQUE constraint.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试向具有唯一约束的列插入重复值。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Ignoring the error and retrying the commit",
      "why_fails": "Same error will occur if duplicate data is not resolved.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Removing the UNIQUE constraint from the database",
      "why_fails": "Compromises data integrity; allows duplicate emails.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check for existing record before insertion",
      "success_rate": 0.95,
      "how": "existing = User.query.filter_by(email=email).first()\nif not existing:\n    db.session.add(new_user)\n    db.session.commit()",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use save-or-update logic",
      "success_rate": 0.9,
      "how": "user = User.query.filter_by(email=email).first()\nif user:\n    user.name = name\nelse:\n    user = User(email=email, name=name)\ndb.session.add(user)\ndb.session.commit()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}