Fixed incorrect query when uploading media with an existing name.