Handle constraint errors gracefully.