我一直在尝试从 python 将数据插入 MYSQL 表。我的sql表中的字段是id、token、start_time、end_time和no_of_trans。
我想存储使用生成的令牌uuid4
在令牌栏中。但由于该值包含(-)
,我收到此错误:mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column '3900af75' in 'field list''
其中生成的令牌是:3900af75-4563-4c05-81ba-b0f1630abecc
而且我也尝试过以字符串格式插入日期,但这也不起作用。所以我明确地将日期值作为字符串传递: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))
它将数据插入表中,但日期被视为整数,并且存储的值是1996
这只不过是2020-04
从我过去之日起。
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 | |
+-------------+--------------+------+-----+---------+----------------+