Manual purge: "Cannot delete or update a parent row: a foreign key constraint fails"

When doing a manual purge I am getting the following error:

Error executing query: (MySQLdb.IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_FK_0_0` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`) ON DELETE NO ACTION ON UPDATE NO ACTION)')

And my database is getting pretty big:

Running MariaDB version 2.5.1

What version of Home Assistant Core has the issue?

Home Assistant 2022.11.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

MariaDB 2.5.1

Example YAML snippet

service: recorder.purge
data:
  keep_days: 7

Anything in the logs that might be useful for us?

Unhandled database error while processing task PurgeTask(purge_before=datetime.datetime(2022, 9, 7, 17, 52, 19, 322235, tzinfo=datetime.timezone.utc), repack=False, apply_filter=False): (MySQLdb.IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_FK_0_0` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`) ON DELETE NO ACTION ON UPDATE NO ACTION)') [SQL: DELETE FROM events WHERE events.event_id IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: (16459781, 16459782, 16459783, 16459784, 16435216, 16435217, 16435218, 16435219, 16435220, 16443415, 16443416, 16443417, 16443418, 16605216, 16605217, 16605218, 16605219, 16605220, 16605221, 16605222, 16605223, 16603818, 16605224, 16605225, 16605226, 16605227, 16603819, 16605228, 16605229, 16605230, 16605231, 16603820, 16605232, 16605233, 16605234, 16605235, 16605236, 16556105, 16527440, 16527441, 16543825, 16543826, 16543827, 16603216, 16541782, 16603217, 16547937, 16547938, 16547939, 16547940, 16547941, 16547942, 16547943, 16601216, 16601217, 16601218, 16601219, 16601220, 16601221, 16601222, 16601223, 16601224, 16601225, 16601226, 16601227, 16601228, 16601229, 16601230, 16601231, 16601232, 16601233, 16601234, 16601235, 16601236, 16601237, 16601238, 16601239, 16599216, 16599217, 16443570, 16443571, 16443572, 16443573, 16443574, 16443575, 16443576, 16443577, 16443578, 16443579, 16443580, 16443581, 16443582, 16443583, 16443584, 16443585, 16427216, 16427217, 16427218, 16427219, 16427220, 16427221, 16427222, 16427223, 16427224, 16427225, 16427226, 16427227, 16427228, 16427229, 16427230, 16427231, 16427232, 16427233, 16427234, 16427235, 16427236, 16427237, 16427238, 16427239, 16427240, 16427241, 16427242, 16427243, 16427244, 16427245, 16427246, 16427247, 16427248, 16427249, 16468216, 16468217, 16468218, 16509216, 16423216, 16423217, 16605490, 16605491, 16605492, 16605493, 16605494, 16605495, 16605496, 16605497, 16605498, 16605499, 16605500, 16605501, 16605502, 16605503, 16605504, 16605505, 16605506, 16605507, 16605508, 16605509, 16605510, 16605511, 16605512, 16605513, 16605514, 16605515, 16605516, 16605517, 16605518, 16603482, 16603483, 16603484, 16527732, 16542069, 16542070, 16601463, 16601464, 16601465, 16601466, 16505216, 16505217, 16505218, 16505219, 16505220, 16505221, 16505222, 16505223, 16505224, 16505225, 16505226, 16598190, 16419216, 16503216, 16503217, 16503218, 16503219, 16503220, 16503221, 16503222, 16503223, 16503224, 16503225, 16503226, 16468410, 16468411, 16468412, 16503230, 16468413, 16468414, 16468415, 16468416, 16468417, 16468418, 16468419, 16503229, 16503231, 16503232, 16503233, 16501216, 16458216, 16458217, 16597484, 16597485, 16597486, 16437743, 16585216, 16585217, 16585218, 16585219, 16531998, 16413216, 16413217, 16413218, 16413219, 16413220, 16413221, 16413222, 16413223, 16413224, 16413225, 16413226, 16413227, 16413228, 16413229, 16413230, 16413231, 16413232, 16583216, 16583217, 16583218, 16583219, 16605751, 16605752, 16497216, 16411218, 16411219, 16411220, 16411221, 16411222, 16411223, 16411224, 16411225, 16411226, 16411227, 16411228, 16411229, 16411230, 16411231, 16411232, 16411233, 16411234, 16411235, 16411236, 16411237, 16411238, 16565417, 16583281, 16583282, 16565418, 16493216, 16493217, 16493218, 16493219, 16493220, 16493221, 16493222, 16493223, 16493224, 16493225, 16493226, 16493227, 16493228, 16493229, 16493230, 16493231, 16493232, 16493233, 16493234, 16493235, 16493236, 16493237, 16493238, 16577216, 16577217, 16577218, 16577219, 16577220, 16585434, 16413405, 16413406, 16413407, 16493283, 16493284, 16493285, 16493286, 16577254, 16577255, 16577256, 16423661, 16423662, 16423663, 16423664, 16458477, 16575216, 16575217, 16575218, 16575219, 16575220, 16575221, 16575222, 16423673, 16423674, 16423675, 16423676, 16423677, 16423678, 16423679, 16423680, 16423681, 16423682, 16423683, 16423684, 16423685, 16423686, 16423687, 16423688, 16423689, 16423690, 16423691, 16444174, 16427798, 16427799, 16573216, 16573217, 16573218, 16573219, 16573220, 16573221, 16573222, 16573223, 16573224, 16573225, 16573226, 16573227, 16573228, 16573229, 16573230, 16573231, 16487216, 16573232, 16573233, 16573234, 16573235, 16573236, 16573237, 16573238, 16573239, 16573240, 16573241, 16573242, 16614560, 16614216, 16614217, 16614219, 16614220, 16614221, 16614222, 16614223, 16571216, 16614224, 16614561, 16614562, 16614563, 16419675, 16436072, 16436073, 16436074, 16436075, 16436076, 16436077, 16436078, 16436079, 16606060, 16606061, 16606062, 16606063, 16606064, 16606065, 16606066, 16606067, 16606068, 16483216, 16483217, 16483218, 16573351, 16573352, 16573353, 16602027, 16509868, 16509869, 16509870, 16509871, 16567216, 16567217, 16567218, 16602028, 16583631, 16565216, 16565217, 16565218, 16413689, 16604162, 16563216, 16563217, 16563218, 16563219, 16563220, 16563221, 16563222, 16563223, 16563224, 16563225, 16567346, 16567347, 16585787, 16585788, 16577599, 16561216, 16561217, 16561218, 16561219, 16561220, 16561221, 16561222, 16577600, 16577601, 16577602, 16475216, 16475217, 16475218, 16475219, 16475220, 16475221, 16475222, 16475223, 16475224, 16475225, 16475226, 16559216, 16559217, 16559218, 16559219, 16559220, 16559221, 16559222, 16559223, 16559224, 16559225, 16559226, 16559227, 16559228, 16559229, 16559230, 16559231, 16559232, 16559233, 16559234, 16559235, 16559236, 16559237, 16559238, 16614549, 16614550, 16614551, 16614552, 16614553, 16614554, 16614555, 16614556, 16614557, 16614558, 16614559, 16557216, 16557217, 16557218, 16557219, 16557220, 16557221, 16557222, 16557223, 16557224, 16557225, 16557226, 16557227, 16557228, 16557229, 16557230, 16557231, 16557232, 16557233, 16557234, 16557235, 16557236, 16557237, 16557238, 16557239, 16557240, 16557241, 16557242, 16557243, 16557244, 16510141, 16510142, 16510143, 16510144, 16510145, 16510146, 16510147, 16510148, 16510149, 16510150, 16510151, 16510152, 16510153, 16510154, 16510155, 16510156, 16510157, 16510158, 16510159, 16510160, 16510161, 16510162, 16555216, 16555217, 16555218, 16555219, 16555220, 16555221, 16555222, 16555223, 16555224, 16555225, 16555226, 16555227, 16555228, 16555229, 16555230, 16506090, 16553216, 16553217, 16553218, 16553219, 16553243, 16553244, 16553245, 16594216, 16594217, 16594218, 16594219, 16594220, 16594221, 16594222, 16594223, 16551216, 16594224, 16594225, 16594226, 16594227, 16594228, 16594229, 16594230, 16567608, 16567609, 16567610, 16567611, 16594231, 16594232, 16594233, 16594234, 16594235, 16594236, 16594237, 16594238, 16594239, 16565408, 16565409, 16565410, 16565411, 16565412, 16565413, 16565414, 16565415, 16565416, 16463216, 16463217, 16463218, 16463219, 16463220, 16463221, 16463222, 16463223, 16463224, 16463225, 16463226, 16463227, 16463228, 16463229, 16463230, 16463231, 16463232, 16463233, 16463234, 16565419, 16565420, 16565421, 16565422, 16498061, 16547216, 16565423, 16565424, 16565425, 16461216, 16565426, 16586145, 16586146, 16586147, 16586148, 16565684, 16551351, 16551352, 16551353, 16551354, 16551355, 16545216, 16545217, 16599218, 16459216, 16487907, 16487908, 16543216, 16543217, 16543218, 16543219, 16543220, 16543221, 16543222, 16543223, 16543224, 16543225, 16543226, 16543227, 16543228, 16543229, 16543230, 16543231, 16457216, 16457217, 16543232, 16543233, 16543234, 16457221, 16543235, 16543236, 16543237, 16543238, 16543239, 16543240, 16543241, 16543242, 16543243, 16543244, 16543245, 16543246, 16543247, 16543248, 16541216, 16541217, 16541218, 16541219, 16475686, 16475687, 16475688, 16475689, 16455216, 16455217, 16567898, 16567899, 16578141, 16453216, 16453217, 16453218, 16453219, 16453220, 16453221, 16453222, 16453223, 16453224, 16453225, 16453226, 16453227, 16453228, 16453229, 16453230, 16453231, 16597216, 16545425, 16545426, 16459447, 16463548, 16463549, 16563910, 16563911, 16563912, 16563913, 16563914, 16484043, 16563915, 16563916, 16563917, 16547591, 16547592, 16547593, 16547594, 16531216, 16555808, 16541486, 16503227, 16503228, 16547661, 16547662, 16547663, 16443216, 16557245, 16527216, 16527217, 16527218, 16527219, 16441216, 16525216, 16525217, 16525218, 16525219, 16525220, 16525221, 16525222, 16525223, 16525224, 16525225, 16594890, 16594891, 16594892, 16594893, 16594894, 16594895, 16594896, 16463826, 16463827, 16463828, 16463829, 16463830, 16463831, 16463832, 16463833, 16463834, 16463835, 16463836, 16463837, 16463838, 16463839, 16437216, 16463840, 16463841, 16463842, 16463843, 16463844, 16463845, 16463846, 16463847, 16547824, 16547825, 16547826, 16547827, 16547828, 16547829)] (Background on this error at: https://sqlalche.me/e/14/gkpj)

and:

 Error executing query: (MySQLdb.IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_FK_0_0` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`) ON DELETE NO ACTION ON UPDATE NO ACTION)') [SQL: DELETE FROM events WHERE events.event_id IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)] [parameters: (16459781, 16459782, 16459783, 16459784, 16435216, 16435217, 16435218, 16435219, 16435220, 16443415, 16443416, 16443417, 16443418, 16605216, 16605217, 16605218, 16605219, 16605220, 16605221, 16605222, 16605223, 16603818, 16605224, 16605225, 16605226, 16605227, 16603819, 16605228, 16605229, 16605230, 16605231, 16603820, 16605232, 16605233, 16605234, 16605235, 16605236, 16556105, 16527440, 16527441, 16543825, 16543826, 16543827, 16603216, 16541782, 16603217, 16547937, 16547938, 16547939, 16547940, 16547941, 16547942, 16547943, 16601216, 16601217, 16601218, 16601219, 16601220, 16601221, 16601222, 16601223, 16601224, 16601225, 16601226, 16601227, 16601228, 16601229, 16601230, 16601231, 16601232, 16601233, 16601234, 16601235, 16601236, 16601237, 16601238, 16601239, 16599216, 16599217, 16443570, 16443571, 16443572, 16443573, 16443574, 16443575, 16443576, 16443577, 16443578, 16443579, 16443580, 16443581, 16443582, 16443583, 16443584, 16443585, 16427216, 16427217, 16427218, 16427219, 16427220, 16427221, 16427222, 16427223, 16427224, 16427225, 16427226, 16427227, 16427228, 16427229, 16427230, 16427231, 16427232, 16427233, 16427234, 16427235, 16427236, 16427237, 16427238, 16427239, 16427240, 16427241, 16427242, 16427243, 16427244, 16427245, 16427246, 16427247, 16427248, 16427249, 16468216, 16468217, 16468218, 16509216, 16423216, 16423217, 16605490, 16605491, 16605492, 16605493, 16605494, 16605495, 16605496, 16605497, 16605498, 16605499, 16605500, 16605501, 16605502, 16605503, 16605504, 16605505, 16605506, 16605507, 16605508, 16605509, 16605510, 16605511, 16605512, 16605513, 16605514, 16605515, 16605516, 16605517, 16605518, 16603482, 16603483, 16603484, 16527732, 16542069, 16542070, 16601463, 16601464, 16601465, 16601466, 16505216, 16505217, 16505218, 16505219, 16505220, 16505221, 16505222, 16505223, 16505224, 16505225, 16505226, 16598190, 16419216, 16503216, 16503217, 16503218, 16503219, 16503220, 16503221, 16503222, 16503223, 16503224, 16503225, 16503226, 16468410, 16468411, 16468412, 16503230, 16468413, 16468414, 16468415, 16468416, 16468417, 16468418, 16468419, 16503229, 16503231, 16503232, 16503233, 16501216, 16458216, 16458217, 16597484, 16597485, 16597486, 16437743, 16585216, 16585217, 16585218, 16585219, 16531998, 16413216, 16413217, 16413218, 16413219, 16413220, 16413221, 16413222, 16413223, 16413224, 16413225, 16413226, 16413227, 16413228, 16413229, 16413230, 16413231, 16413232, 16583216, 16583217, 16583218, 16583219, 16605751, 16605752, 16497216, 16411218, 16411219, 16411220, 16411221, 16411222, 16411223, 16411224, 16411225, 16411226, 16411227, 16411228, 16411229, 16411230, 16411231, 16411232, 16411233, 16411234, 16411235, 16411236, 16411237, 16411238, 16565417, 16583281, 16583282, 16565418, 16493216, 16493217, 16493218, 16493219, 16493220, 16493221, 16493222, 16493223, 16493224, 16493225, 16493226, 16493227, 16493228, 16493229, 16493230, 16493231, 16493232, 16493233, 16493234, 16493235, 16493236, 16493237, 16493238, 16577216, 16577217, 16577218, 16577219, 16577220, 16585434, 16413405, 16413406, 16413407, 16493283, 16493284, 16493285, 16493286, 16577254, 16577255, 16577256, 16423661, 16423662, 16423663, 16423664, 16458477, 16575216, 16575217, 16575218, 16575219, 16575220, 16575221, 16575222, 16423673, 16423674, 16423675, 16423676, 16423677, 16423678, 16423679, 16423680, 16423681, 16423682, 16423683, 16423684, 16423685, 16423686, 16423687, 16423688, 16423689, 16423690, 16423691, 16444174, 16427798, 16427799, 16573216, 16573217, 16573218, 16573219, 16573220, 16573221, 16573222, 16573223, 16573224, 16573225, 16573226, 16573227, 16573228, 16573229, 16573230, 16573231, 16487216, 16573232, 16573233, 16573234, 16573235, 16573236, 16573237, 16573238, 16573239, 16573240, 16573241, 16573242, 16614560, 16614216, 16614217, 16614219, 16614220, 16614221, 16614222, 16614223, 16571216, 16614224, 16614561, 16614562, 16614563, 16419675, 16436072, 16436073, 16436074, 16436075, 16436076, 16436077, 16436078, 16436079, 16606060, 16606061, 16606062, 16606063, 16606064, 16606065, 16606066, 16606067, 16606068, 16483216, 16483217, 16483218, 16573351, 16573352, 16573353, 16602027, 16509868, 16509869, 16509870, 16509871, 16567216, 16567217, 16567218, 16602028, 16583631, 16565216, 16565217, 16565218, 16413689, 16604162, 16563216, 16563217, 16563218, 16563219, 16563220, 16563221, 16563222, 16563223, 16563224, 16563225, 16567346, 16567347, 16585787, 16585788, 16577599, 16561216, 16561217, 16561218, 16561219, 16561220, 16561221, 16561222, 16577600, 16577601, 16577602, 16475216, 16475217, 16475218, 16475219, 16475220, 16475221, 16475222, 16475223, 16475224, 16475225, 16475226, 16559216, 16559217, 16559218, 16559219, 16559220, 16559221, 16559222, 16559223, 16559224, 16559225, 16559226, 16559227, 16559228, 16559229, 16559230, 16559231, 16559232, 16559233, 16559234, 16559235, 16559236, 16559237, 16559238, 16614549, 16614550, 16614551, 16614552, 16614553, 16614554, 16614555, 16614556, 16614557, 16614558, 16614559, 16557216, 16557217, 16557218, 16557219, 16557220, 16557221, 16557222, 16557223, 16557224, 16557225, 16557226, 16557227, 16557228, 16557229, 16557230, 16557231, 16557232, 16557233, 16557234, 16557235, 16557236, 16557237, 16557238, 16557239, 16557240, 16557241, 16557242, 16557243, 16557244, 16510141, 16510142, 16510143, 16510144, 16510145, 16510146, 16510147, 16510148, 16510149, 16510150, 16510151, 16510152, 16510153, 16510154, 16510155, 16510156, 16510157, 16510158, 16510159, 16510160, 16510161, 16510162, 16555216, 16555217, 16555218, 16555219, 16555220, 16555221, 16555222, 16555223, 16555224, 16555225, 16555226, 16555227, 16555228, 16555229, 16555230, 16506090, 16553216, 16553217, 16553218, 16553219, 16553243, 16553244, 16553245, 16594216, 16594217, 16594218, 16594219, 16594220, 16594221, 16594222, 16594223, 16551216, 16594224, 16594225, 16594226, 16594227, 16594228, 16594229, 16594230, 16567608, 16567609, 16567610, 16567611, 16594231, 16594232, 16594233, 16594234, 16594235, 16594236, 16594237, 16594238, 16594239, 16565408, 16565409, 16565410, 16565411, 16565412, 16565413, 16565414, 16565415, 16565416, 16463216, 16463217, 16463218, 16463219, 16463220, 16463221, 16463222, 16463223, 16463224, 16463225, 16463226, 16463227, 16463228, 16463229, 16463230, 16463231, 16463232, 16463233, 16463234, 16565419, 16565420, 16565421, 16565422, 16498061, 16547216, 16565423, 16565424, 16565425, 16461216, 16565426, 16586145, 16586146, 16586147, 16586148, 16565684, 16551351, 16551352, 16551353, 16551354, 16551355, 16545216, 16545217, 16599218, 16459216, 16487907, 16487908, 16543216, 16543217, 16543218, 16543219, 16543220, 16543221, 16543222, 16543223, 16543224, 16543225, 16543226, 16543227, 16543228, 16543229, 16543230, 16543231, 16457216, 16457217, 16543232, 16543233, 16543234, 16457221, 16543235, 16543236, 16543237, 16543238, 16543239, 16543240, 16543241, 16543242, 16543243, 16543244, 16543245, 16543246, 16543247, 16543248, 16541216, 16541217, 16541218, 16541219, 16475686, 16475687, 16475688, 16475689, 16455216, 16455217, 16567898, 16567899, 16578141, 16453216, 16453217, 16453218, 16453219, 16453220, 16453221, 16453222, 16453223, 16453224, 16453225, 16453226, 16453227, 16453228, 16453229, 16453230, 16453231, 16597216, 16545425, 16545426, 16459447, 16463548, 16463549, 16563910, 16563911, 16563912, 16563913, 16563914, 16484043, 16563915, 16563916, 16563917, 16547591, 16547592, 16547593, 16547594, 16531216, 16555808, 16541486, 16503227, 16503228, 16547661, 16547662, 16547663, 16443216, 16557245, 16527216, 16527217, 16527218, 16527219, 16441216, 16525216, 16525217, 16525218, 16525219, 16525220, 16525221, 16525222, 16525223, 16525224, 16525225, 16594890, 16594891, 16594892, 16594893, 16594894, 16594895, 16594896, 16463826, 16463827, 16463828, 16463829, 16463830, 16463831, 16463832, 16463833, 16463834, 16463835, 16463836, 16463837, 16463838, 16463839, 16437216, 16463840, 16463841, 16463842, 16463843, 16463844, 16463845, 16463846, 16463847, 16547824, 16547825, 16547826, 16547827, 16547828, 16547829)] (Background on this error at: https://sqlalche.me/e/14/gkpj)

I fixed it manually by finding the keys using:

SELECT *
FROM information_schema.table_constraints
WHERE constraint_schema = 'homeassistant'

In my case key states_FK_0_0 was wrong so I executed:

ALTER TABLE states
DROP FOREIGN KEY states_FK_0_0; 

And that did solve this error.

1 Like