Details:
Error:
insert_data = "INSERT INTO users VALUES (?, ?, ?)"
user = [
{1, "Ram", "abc@123"},
{2, "Rahim", "wel@123"},
{3, "Raju", "pass@123"}
]
cursor.executemany(insert_data, user)
When you run the above code you will get the error:
(venv) D:\python\Course_sample\source_database>python dataBase.py
parameters are of unsupported type
This is because when ever we try to insert into database from python, they data has to be a tuple.
In the above code you can see list of set which we try to insert.
Fixed:
#insert data query
insert_data = "INSERT INTO users VALUES (?, ?, ?)"
user = [
(1, "Ram", "abc@123"),
(2, "Rahim", "wel@123"),
(3, "Raju", "pass@123")
]
cursor.executemany(insert_data, user)
The above code will get executed and the data will get inserted into the database properly.
No comments:
Post a Comment