Jibin
Jibin

Reputation: 464

python Insert tupule value to mysql database

I need to install tupule value to database,but getting "Unknown column 'Mac' in 'field list'" error Below is the code i used

import  mysql.connector, csv, sys
conn  = mysql.connector.connect(
  host="localhost",
  user="root",
  passwd="root",
  database="mydjangoapp",
  port=3307,

)
cursor=conn.cursor()
t1=('Mac', 'Mohan')
sql="insert into books (title,isbn)  values(%s,%s)" %t1

cursor.execute(sql)

Upvotes: 1

Views: 49

Answers (1)

AKX
AKX

Reputation: 169051

Don't use % interpolation, use placeholders.

t1 = ('Mac', 'Mohan',)
cursor.execute("INSERT INTO books (title, isbn) VALUES (%s, %s)", t1)

Upvotes: 3

Related Questions