Fixed a MySQL issue with a migration which used a distinct query

MySQL does not support distinct, and it’s not critical, so I’ve just
done a try except statement which will just use read permissions on a
fail.