State history not available for any sensor

I recently installed add-on SQLite web for a short period to check something out. That worked out OK but I started getting errors (which I didn’t record) saying something about SQL errors. I removed SQLite web but the system has become very odd - none of my history graphs are working (all blank) and I can’t display the history of any sensor. I’ve retarted a few times, re-booted the HA server, even re-installed SQLite web. The latter can see the home-assistant_v2 database contents apparently OK. I’m also getting frequent errors from the Octopus energy integration Update for sensor.octopus_energy_electricity_21l4277849_2200011560050_previous_accumulative_consumption fails which sounds like a problem with history.
** edit ** I just found many lines like this in home-asstitant.log.1

2025-09-29 18:33:40.669 WARNING (Recorder) [homeassistant.components.recorder.util] The system could not validate that the sqlite3 database at //config/home-assistant_v2.db was shutdown cleanly
2025-09-29 18:33:41.604 ERROR (DbWorker_0) [homeassistant.components.recorder.util] Error executing query: (sqlite3.OperationalError) no such column: states_meta.entity_id
[SQL: SELECT states_meta.metadata_id, states_meta.entity_id 
FROM states_meta 
WHERE states_meta.entity_id IN (?)]
[parameters: ('binary_sensor.slwisrestricted',)]

Using SQLite to inspect the structure of states_meta there is indeed no such column & the documentation says that is an outdated feature.

It looks like it is related to these errors I’ getting; I thought they were related to the Octopus Energy integration, but the owner of that says it is an error deep in HA itself. Every 30 seconds its logging errors like this:

025-09-30 14:39:28.280 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.octopus_energy_electricity_21l4277849_2200011560050_previous_accumulative_consumption fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 963, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1314, in async_device_update
await self.async_update()
File "/config/custom_components/octopus_energy/electricity/previous_accumulative_consumption.py", line 152, in async_update
await async_import_external_statistics_from_consumption(
...<8 lines>...
)
File "/config/custom_components/octopus_energy/statistics/consumption.py", line 54, in async_import_external_statistics_from_consumption
latest_total_sum = initial_statistics.total if initial_statistics is not None else await async_get_last_sum(hass, consumptions[0]["start"], statistic_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/octopus_energy/statistics/init.py", line 103, in async_get_last_sum
last_total_stat = await get_instance(hass).async_add_executor_job(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
statistics_during_period,
^^^^^^^^^^^^^^^^^^^^^^^^^
...<6 lines>...
{"sum"}
^^^^^^^
)
^
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 359, in async_add_executor_job
return self.hass.loop.run_in_executor(self._db_executor, target, *args)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/asyncio/base_events.py", line 901, in run_in_executor
executor.submit(func, *args), loop=self)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 171, in submit
raise RuntimeError('cannot schedule new futures after shutdown')
RuntimeError: cannot schedule new futures after shutdown

It looks to me to be a problem with the database structure, maybe a mismatch between the new version where states_meta has a column called states_meta.entity_id and the current version that does not.