home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.11k stars 29.16k forks source link

Recorder gets stuck after purge until restart of HA #43510

Closed embcla closed 3 years ago

embcla commented 3 years ago

The problem

Sometimes the logger gets stuck basically tearing down the entire home assistant core. I notice it because I hear the harddrives churning, and when I get to HA the UI is extremely slow (to the point of being almost unresponsive). It always starts at 4:12, though I don't run services at that specific time. It almost never recovers by itself, in fact this has happened a number of times since I moved to mariadb, and only once I saw this error in the logs appearing only once, all other times the system gets stuck generating it in loop thousands of times until I catch it.

HA is running in supervised on a debian VM on my NAS, and mariaDB in a container on the same NAS. NAS is an AMD based quad core x86 based on linux. When the error is going on, the NAS shows increased cpu and I/O activity by debian as shown in these pictures

Screenshot 2020-11-22 at 08 28 43 Screenshot 2020-11-22 at 08 28 25

Environment

System Health

Home Assistant Core Integration

version: 0.118.0
installation_type: Home Assistant Supervised
dev: false
hassio: true
docker: true
virtualenv: false
python_version: 3.8.6
os_name: Linux
os_version: 4.19.0-11-amd64
arch: x86_64
timezone: blabla

Home Assistant Cloud

logged_in: true
subscription_expiration: 2 December 2020, 1:00
relayer_connected: true
remote_enabled: true
remote_connected: true
alexa_enabled: false
google_enabled: false
can_reach_cert_server: ok
can_reach_cloud_auth: ok
can_reach_cloud: ok

Home Assistant Supervisor

host_os: Debian GNU/Linux 10 (buster)
update_channel: stable
supervisor_version: 2020.11.0
docker_version: 19.03.13
disk_total: 56.8 GB
disk_used: 9.6 GB
healthy: true
supported: true
supervisor_api: ok
version_api: ok
installed_addons: deCONZ (6.5.0), FTP (3.5.0), OpenZWave (0.5.2), Mosquitto broker (5.1), Z-Wave to MQTT (0.8.3), File editor (5.2.0), Check Home Assistant configuration (3.6.0), room-assistant (2.12.0), AirSonos (2.4.0), Visual Studio Code (2.8.2), Dnsmasq (1.3)

Lovelace

dashboards: 2
mode: auto-gen
resources: 7

Problem-relevant configuration.yaml


recorder:
  db_url: mysql://user:pass@ip/homeassistant
  purge_keep_days: 7
  exclude:    # Eliminate anything that you never graph or refer back to
    domains:
      - automation
      - updater
    entities:
      - sun.sun
      - sensor.time
      - sensor.date_time_iso # Don't record date and time
      - sensor.yr_symbol # Ignore this as well
      - group.weather # Don't save weather 

Traceback/Error logs

Logger: homeassistant.components.recorder
Source: components/recorder/__init__.py:509
Integration: Recorder (documentation, issues)
First occurred: 4:12:05 (1834 occurrences)
Last logged: 8:12:32

Error saving events: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.qnapups_input_voltage', '229.0', '{"state": "Online", "unit_of_measurement": "V", "friendly_name": "Qnapups Input Voltage", "icon": "mdi:flash"}', 10910582, datetime.datetime(2020, 11, 22, 3, 47, 1, 7390, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 47, 1, 7390, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 47, 1, 7390, tzinfo=datetime.timezone.utc), 10670589)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error saving events: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.unifi_dream_machine_b_sent', '74842624834', '{"unit_of_measurement": "B", "friendly_name": "UniFi Dream Machine B sent", "icon": "mdi:server-network"}', 10908391, datetime.datetime(2020, 11, 22, 3, 39, 11, 27251, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 39, 11, 27251, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 39, 11, 27251, tzinfo=datetime.timezone.utc), 10671082)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error saving events: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.iotawatt', '230.44', '{"inputs": [{"channel": 0, "Vrms": 230.44, "Hz": 49.9851, "phase": 1.48}, {"channel": 1, "Watts": " 0", "Pf": 0, "phase": 1.4, "lastphase": -0.08}, { ... (1507 characters truncated) ... its": "Watts", "value": 273.6615}, {"name": "voltaggio", "units": "Volts", "value": 230.44}], "friendly_name": "IoTaWatt", "device_class": "voltage"}', 10900935, datetime.datetime(2020, 11, 22, 3, 12, 4, 208286, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 12, 4, 208286, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 12, 4, 208286, tzinfo=datetime.timezone.utc), 10669729)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error saving events: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.claudio_s_galaxy_s10_room_presence', 'Garage', '{"distance": 2.9, "last_updated_at": "2020-11-22T03:19:49.395Z", "friendly_name": "Claudio\'s Galaxy S10+ Room Presence", "icon": "mdi:bluetooth"}', 10903077, datetime.datetime(2020, 11, 21, 22, 26, 10, 330368, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 19, 49, 398821, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 19, 49, 398821, tzinfo=datetime.timezone.utc), 10670117)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error saving events: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.iphone_di_alessandra_room_presence', 'Sala', '{"distance": 0, "last_updated_at": "2020-11-22T03:18:19.101Z", "friendly_name": "iPhone di Alessandra Room Presence", "icon": "mdi:bluetooth"}', 10902661, datetime.datetime(2020, 11, 21, 22, 50, 17, 24132, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 18, 19, 106547, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 18, 19, 106547, tzinfo=datetime.timezone.utc), 10670040)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 454, in _commit_event_session_or_retry
    self._commit_event_session()
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 509, in _commit_event_session
    self.event_session.flush()
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2536, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2678, in _flush
    transaction.rollback(_capture_exception=True)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2638, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
    rec.execute(self)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 586, in execute
    persistence.save_obj(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 239, in save_obj
    _emit_insert_statements(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1135, in _emit_insert_statements
    result = cached_connections[connection].execute(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
    ret = self._execute_context(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
    self._handle_dbapi_exception(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
    util.raise_(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
    cursor.execute(statement, parameters)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
sqlalchemy.exc.IntegrityError: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))')
[SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)]
[parameters: ('sensor', 'sensor.iotawatt', '230.44', '{"inputs": [{"channel": 0, "Vrms": 230.44, "Hz": 49.9851, "phase": 1.48}, {"channel": 1, "Watts": " 0", "Pf": 0, "phase": 1.4, "lastphase": -0.08}, { ... (1507 characters truncated) ... its": "Watts", "value": 273.6615}, {"name": "voltaggio", "units": "Volts", "value": 230.44}], "friendly_name": "IoTaWatt", "device_class": "voltage"}', 10900935, datetime.datetime(2020, 11, 22, 3, 12, 4, 208286, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 12, 4, 208286, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 22, 3, 12, 4, 208286, tzinfo=datetime.timezone.utc), 10669729)]
(Background on this error at: http://sqlalche.me/e/13/gkpj)
Connection lost. Reconnecting…

mariadb shows no error in the container logs but the resets when rebooting HA

2020-11-11 23:39:39 1027 [Warning] Aborted connection 1027 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-11 23:39:39 1028 [Warning] Aborted connection 1028 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-11 23:39:39 1026 [Warning] Aborted connection 1026 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-11 23:39:39 1029 [Warning] Aborted connection 1029 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-11 23:39:39 1023 [Warning] Aborted connection 1023 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-20  7:46:29 1144 [Warning] Aborted connection 1144 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-20  7:46:29 1153 [Warning] Aborted connection 1153 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-20  7:46:29 1135 [Warning] Aborted connection 1135 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-20  7:46:35 1146 [Warning] Aborted connection 1146 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-20  7:47:04 1149 [Warning] Aborted connection 1149 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-20  7:47:04 1152 [Warning] Aborted connection 1152 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-20 12:43:39 1163 [Warning] Access denied for user 'root'@'localhost' (using password: NO)

2020-11-22  8:26:53 1174 [Warning] Aborted connection 1174 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-22  8:26:53 1170 [Warning] Aborted connection 1170 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-22  8:26:53 1171 [Warning] Aborted connection 1171 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-22  8:26:53 1173 [Warning] Aborted connection 1173 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

2020-11-22  8:26:56 1172 [Warning] Aborted connection 1172 to db: 'homeassistant' user: 'hassio' host: '192.168.101.4' (Got an error reading communication packets)

and the processlist before the reset looks like this

 mysql> show processlist;
+------+--------+---------------------+---------------+---------+------+----------+------------------+----------+
| Id   | User   | Host                | db            | Command | Time | State    | Info             | Progress |
+------+--------+---------------------+---------------+---------+------+----------+------------------+----------+
| 1170 | hassio | 192.168.101.4:46524 | homeassistant | Sleep   |   15 |          | NULL             |    0.000 |
| 1171 | hassio | 192.168.101.4:46550 | homeassistant | Sleep   |   88 |          | NULL             |    0.000 |
| 1172 | hassio | 192.168.101.4:46562 | homeassistant | Sleep   |   63 |          | NULL             |    0.000 |
| 1173 | hassio | 192.168.101.4:42520 | homeassistant | Query   |    0 | starting | ROLLBACK         |    0.000 |
| 1174 | hassio | 192.168.101.4:42524 | homeassistant | Sleep   |   39 |          | NULL             |    0.000 |
| 1175 | root   | 192.168.103.9:57894 | NULL          | Query   |    0 | starting | show processlist |    0.000 |
+------+--------+---------------------+---------------+---------+------+----------+------------------+----------+
6 rows in set (0.00 sec)

and after the reset looks like this:

mysql> show processlist;
+------+--------+---------------------+---------------+---------+------+----------+------------------+----------+
| Id   | User   | Host                | db            | Command | Time | State    | Info             | Progress |
+------+--------+---------------------+---------------+---------+------+----------+------------------+----------+
| 1175 | root   | 192.168.103.9:57894 | NULL          | Query   |    0 | starting | show processlist |    0.000 |
| 1176 | hassio | 192.168.101.4:43674 | homeassistant | Sleep   |    0 |          | NULL             |    0.000 |
+------+--------+---------------------+---------------+---------+------+----------+------------------+----------+
2 rows in set (0.00 sec)

Additional information

probot-home-assistant[bot] commented 3 years ago

recorder documentation recorder source (message by IssueLinks)

embcla commented 3 years ago

Here is one of the non repetitive types of recorder errors, time is the same. And it's always both an error and a warning


Source: components/recorder/util.py:43
Integration: Recorder (documentation, issues)
First occurred: 23 November 2020, 4:12:00 (2 occurrences)
Last logged: 4:12:00
Error executing query: (MySQLdb._exceptions.IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: DELETE FROM states WHERE states.last_updated < %s] [parameters: (datetime.datetime(2020, 10, 21, 12, 56, 13, tzinfo=<UTC>),)] (Background on this error at: http://sqlalche.me/e/13/gkpj)

Logger: homeassistant.components.recorder.purge
Source: components/recorder/purge.py:101
Integration: Recorder (documentation, issues)
First occurred: 23 November 2020, 4:12:00 (2 occurrences)
Last logged: 4:12:00

Error purging history: (MySQLdb._exceptions.IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: DELETE FROM states WHERE states.last_updated < %s] [parameters: (datetime.datetime(2020, 10, 21, 12, 56, 13, tzinfo=<UTC>),)] (Background on this error at: http://sqlalche.me/e/13/gkpj)```
bdraco commented 3 years ago

Since these all start at 4:12 it looks like a problem with the auto purge.

slipx06 commented 3 years ago

I am seeing the same error in my logs every couple of days. Recorder stops working. I have to restart home assistant to fix. I'm running 0.118.3 with the MariaDB addon

2020-11-25 10:25:26 ERROR (Recorder) [homeassistant.components.recorder] Error executing query: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (homeassistant.states, CONSTRAINT states_ibfk_2 FOREIGN KEY (old_state_id) REFERENCES states (state_id))')

embcla commented 3 years ago

Today's log

Logger: homeassistant.components.recorder
Source: components/recorder/__init__.py:518
Integration: Recorder (documentation, issues)
First occurred: 4:12:05 (2508 occurrences)
Last logged: 14:03:38

Error executing query: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.memory_use_percent', '43.6', '{"unit_of_measurement": "%", "friendly_name": "Memory use (percent)", "icon": "mdi:memory"}', 12611851, datetime.datetime(2020, 11, 26, 3, 42, 18, 239796, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 3, 42, 18, 239796, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 3, 42, 18, 239796, tzinfo=datetime.timezone.utc), 12344754)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error executing query: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.unifi_dream_machine_b_sent', '85884692872', '{"unit_of_measurement": "B", "friendly_name": "UniFi Dream Machine B sent", "icon": "mdi:server-network"}', 12604736, datetime.datetime(2020, 11, 26, 3, 16, 50, 25074, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 3, 16, 50, 25074, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 3, 16, 50, 25074, tzinfo=datetime.timezone.utc), 12343926)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error executing query: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.nas_bo2_status', 'good', '{"name": "NAS-BO2", "Model": "TS-473", "Serial #": "Q205B43808", "Uptime": "33d 14h 29m", "friendly_name": "NAS-BO2 Status", "icon": "mdi:checkbox-marked-circle-outline"}', 12621541, datetime.datetime(2020, 11, 24, 20, 51, 12, 140078, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 4, 17, 57, 268079, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 4, 17, 57, 268079, tzinfo=datetime.timezone.utc), 12345670)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error executing query: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.iotawatt', '230.4908', '{"inputs": [{"channel": 0, "Vrms": 230.4908, "Hz": 50.00903, "phase": 1.48}, {"channel": 1, "Watts": " 0", "Pf": 0, "phase": 1.4, "lastphase": -0.08} ... (1514 characters truncated) ... s": "Watts", "value": 229.4962}, {"name": "voltaggio", "units": "Volts", "value": 230.4908}], "friendly_name": "IoTaWatt", "device_class": "voltage"}', 12603421, datetime.datetime(2020, 11, 26, 3, 12, 4, 853139, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 3, 12, 4, 853139, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 3, 12, 4, 853139, tzinfo=datetime.timezone.utc), 12343713)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error executing query: (MySQLdb._exceptions.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: INSERT INTO states (domain, entity_id, state, attributes, event_id, last_changed, last_updated, created, old_state_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: ('sensor', 'sensor.cucina_temperature', '16.59', '{"time": "2020-11-26T05:19:31.425Z", "setting": 0, "unit_of_measurement": "\\u00b0C", "friendly_name": "Smart TRV Cucina temperature", "icon": "mdi:thermometer"}', 12638479, datetime.datetime(2020, 11, 26, 5, 19, 37, 874522, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 5, 19, 37, 874522, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 11, 26, 5, 19, 37, 874522, tzinfo=datetime.timezone.utc), 12346921)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
embcla commented 3 years ago

@bdraco has the fix been merged into 118.5? I had the same issue last night as usual