From 1162d9a752267ce493ff1252f417e31f4f54963a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" <nick@koston.org> Date: Sat, 28 Nov 2020 12:54:05 -1000 Subject: [PATCH] Create tables with a charset that can hold all expected data under mysql (#43732) By default these tables are created with utf8 which can only hold 3 bytes. This meant that all emjoi would trigger a MySQLdb._exceptions.OperationalError because they are 4 bytes. This will only fix the issue for users who recreate their tables. --- homeassistant/components/recorder/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/homeassistant/components/recorder/models.py b/homeassistant/components/recorder/models.py index 6c8b6050a9a..5b37f7e3f9d 100644 --- a/homeassistant/components/recorder/models.py +++ b/homeassistant/components/recorder/models.py @@ -42,6 +42,10 @@ ALL_TABLES = [TABLE_STATES, TABLE_EVENTS, TABLE_RECORDER_RUNS, TABLE_SCHEMA_CHAN class Events(Base): # type: ignore """Event history data.""" + __table_args__ = { + "mysql_default_charset": "utf8mb4", + "mysql_collate": "utf8mb4_unicode_ci", + } __tablename__ = TABLE_EVENTS event_id = Column(Integer, primary_key=True) event_type = Column(String(32)) @@ -96,6 +100,10 @@ class Events(Base): # type: ignore class States(Base): # type: ignore """State change history.""" + __table_args__ = { + "mysql_default_charset": "utf8mb4", + "mysql_collate": "utf8mb4_unicode_ci", + } __tablename__ = TABLE_STATES state_id = Column(Integer, primary_key=True) domain = Column(String(64))