Preventing errors due to duplicate entry in the database