@pasqualesimonetti
I believe you would have duplicates in your ost_thread_entry_email
table. You can run the following query to find any duplicates:
SELECT `id`, `thread_entry_id`, COUNT(*) FROM `ost_thread_entry_email` GROUP BY `thread_entry_id` HAVING COUNT(*) > 1;
An example return would be:
+-----+-----------------+------------+
| id | thread_entry_id | COUNT(*) |
+-----+-----------------+------------+
| 1 | 4 | 2 |
+-----+-----------------+------------+
In this example, it tells me that there are two records for ost_thread_entry.id = 4
when there should only be one record. So in this case I would go to the ost_thread_entry_email
table, do a lookup where thread_entry_id = 4
, find which record is not used, and delete it. If there are more than one set of duplicates in the return then repeat the steps for all until there are no duplicates remaining.
Once you do this you should have no more issues. This is of course if MySQL continuously runs indefinitely without reboot. If MySQL goes down or reboots for any reason you may run into this again as you are not running MySQL 8.0+. In versions previous to 8.0 the auto_increment value was stored in memory and not on disk so if MySQL restarts then it loses the auto_increment value and is reset; see this SO post for more info.
With this being said, I'd highly recommend upgrading MySQL to 8.0+.
Cheers.