MySQL Connector/Python Release Notes
This exception is raised when the relational integrity of the data is affected. For example, a duplicate key was inserted or a foreign key constraint would fail.
The following example shows a duplicate key error raised as IntegrityError:
Press CTRL+C to copycursor.execute("CREATE TABLE t1 (id int, PRIMARY KEY (id))") try: cursor.execute("INSERT INTO t1 (id) VALUES (1)") cursor.execute("INSERT INTO t1 (id) VALUES (1)") except mysql.connector.IntegrityError as err: print("Error: {}".format(err))
errors.IntegrityError
is a subclass of
errors.DatabaseError
.