I ave been trying to insert data to MYSQL table from python. The fields in my sql table are id, token, start_time, end_time, and no_of_trans.
I want to store a token generated using uuid4
in the token column. But since the value contains (-)
, I'm getting this error:
mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column '3900af75' in 'field list''
where the token generated is: 3900af75-4563-4c05-81ba-b0f1630abecc
And also I've tried inserting date in string format that also doesn't work. So I explicitly passed the date value as a string:
mycursor.execute("""INSERT INTO generate (token, start_time, end_time, no_of_trans) VALUES (%s, %s, %s, %s)""" %(rand_token, '2020-04-20', '2020-04-20', 3))
Which inserts data into table but date is treated as a integer and the value that gets stored is 1996
which is nothing but 2020-04
from the date I've passed.
Here's the screenshot of my table:
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| token | varchar(255) | YES | | NULL | |
| start_time | varchar(255) | YES | | NULL | |
| end_time | varchar(255) | YES | | NULL | |
| no_of_trans | int(20) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+