{
  "id": "python/sqlalchemy-mysql-charset-issue",
  "signature": "sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1366, \"Incorrect string value: '\\xF0\\x9F\\x98\\x80' for column 'message' at row 1\")",
  "signature_zh": "sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1366, \"第 1 行的 'message' 列出现不正确的字符串值：'\\xF0\\x9F\\x98\\x80'\")",
  "regex": "sqlalchemy\\.exc\\.OperationalError:\\ \\(pymysql\\.err\\.OperationalError\\)\\ \\(1366,\\ \"Incorrect\\ string\\ value:\\ '\\\\xF0\\\\x9F\\\\x98\\\\x80'\\ for\\ column\\ 'message'\\ at\\ row\\ 1\"\\)",
  "domain": "python",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "The database/table/column character set is not utf8mb4, which cannot store 4-byte Unicode characters like emojis.",
  "root_cause_type": "generic",
  "root_cause_zh": "数据库/表/列的字符集不是 utf8mb4，无法存储像表情符号这样的 4 字节 Unicode 字符。",
  "versions": [
    {
      "version": "1.4.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.0.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "utf8 in MySQL is actually utf8mb3, which still doesn't support 4-byte characters.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Corrupts the data.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use charset='utf8mb4' in the connection URL: engine = create_engine('mysql+pymysql://user:pass@host/db?charset=utf8mb4')",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Alter the table to use utf8mb4: ALTER TABLE messages CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}