Please, never ever just go into the db and delete stuff. Almost surely you will leave some orphaned records around, which can lead to issues just like the one you’re having now.
If you insist on removing tasks, please use the provided tooling for doing so. In this case it is the foreman_tasks:cleanup rake task.
Luckily, it removes tasks related orphaned records when it runs so you can use it even now to get your system into working shape.
foreman-rake rake foreman_tasks:cleanup TASK_SEARCH="label = this-label-definitely-does-not-exist"
Running it like this will make it not match any tasks and only perform the cleanup of orphaned records.