'Force python mysql.connector to raise an exception when failing a SQL transaction
Python's mysql.connector does not raise when INSERTing a new row in a table that does not exist, neither it does when the syntax is wrong.
How can I force it to raise?
MWE:
import mysql.connector
connection_params = dict(user="myself", host="localhost")
conn = mysql.connector.connect(**connection_params)
cursor = conn.cursor()
cursor.execute("INSERT INTO TABLE IDontExist (Col1, Col2) VALUES (1, 2)"
conn.close()
When I run this, either into the interpreter or through a script, it just runs. without.
I want the cursor.execute to raise.
Versions: Python: 3.9.7, mysql.connector: 8.0.27, mysql: 8.0.29
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
