It’s strange that this only occurs with mysql… is it possible that you ran the migrations from more than one instance at the same time? In any case, I opened a PR at https://github.com/theforeman/foreman/pull/6862 to try and fix this issue once and for all.
Since you’re a MySQL user, we are considering dropping support for it, so it would be get your feedback on RFC: Dropping support for MySQL as well