check for and handle uniqueness constraint violations