Fix IntegrityError not being raised for Python 3