Fixed upgrade error caused by invalid query.