Having the same issue, just restored HA after latest upgrade last night which trashed the HA completely.
Now trying to fix things and this is one of the many errors.
I have the same problem after restoring HA core. Any ideas how to fix this problem ?
There is problem report in github #133807, but no solution so far. Only the method of removing and adding back wich might causes loosing historic date.