Just ran into this issue again, but this time when merging two tickets. 🙁 The tables all check out and no errors reported by MySQL or the operating system.
MariaDB [osticket]> select * from ost_thread_entry_email where thread_entry_id = 190893;
+--------+-----------------+----------------------------------------------------------------------+---------+
| id | thread_entry_id | mid | headers |
+--------+-----------------+----------------------------------------------------------------------+---------+
| 128920 | 190893 | <20200105110509.51FAF21426@company.com> | NULL |
| 128923 | 190893 | <CANz0cUr-rvX-_0diaOR8mtK=WEoXbysUTw@mail.gmail.com> | NULL |
+--------+-----------------+----------------------------------------------------------------------+---------+
Curious thing to note, the "id" values are 3 apart, so lets see what happened inbetween there:
MariaDB [osticket]> select * from ost_thread_entry_email where id >= 128920 and id <= 128923;
+--------+-----------------+----------------------------------------------------------------------+---------+
| id | thread_entry_id | mid | headers |
+--------+-----------------+----------------------------------------------------------------------+---------+
| 128920 | 190893 | <20200105110509.51FAF21426@company.com> | NULL |
| 128921 | 190894 | <20200105110509.5F8CE24EA7@company.com> | NULL |
| 128922 | 190892 | <CANz0cUpgJPVkoMxD2V=hrWV8W1-Eym8j7w@mail.gmail.com> | NULL |
| 128923 | 190893 | <CANz0cUr-rvX-_0diaOR8mtK=WEoXbysUTw@mail.gmail.com> | NULL |
+--------+-----------------+----------------------------------------------------------------------+---------+
Interestingly, ID=128920 has THREAD_ENTRY_ID=190893 yet ID=128922 which had to be inserted after that record has an earlier THREAD_ENTRY_ID=190892.
This sure smells like a race condition in how osTicket is handling these IDs, especially since thread_entry_id is not an auto-incrementing column itself, so its value must be obtained elsewhere and explicitly inserted into this table .