I am trying to insert with python (v 2.7.6) a variable with multiple entries into mysql (Ver 14.14 Distrib 5.5.43) table. The code is as follows :
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS Stations( \
StationsID INT AUTO_INCREMENT, \
Code VARCHAR(3) , \
PRIMARY KEY pk_Stations (StationsID) \
);");
cur.executemany("INSERT INTO Stations (Code) VALUES(?)", sns);
sns variable has the following form:array(['PAL', 'TT1', 'BAL', 'MHD', 'BI5', 'CB4'],dtype='|S3')
I am getting the following error: File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 199, in executemany if not args: return ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Could you please give me a help here?
Aucun commentaire :
Enregistrer un commentaire