If this error happened unexpectedly, it could be because of corrupted database tables.
We can fix it with this command from commandline:
And then when the command executed successfully you may run the database repair tool from cacti directory like that: