python 写入mysql时间相关数据报错
我看了半天应该是这个:(冒号的问题),但是我不想改。我之前写的是没问题的,不知道为什么重新换了个方法不行了。还好最后找到问题了。
报错:
1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '13:45:37)' at line 1"
我的mysql语句:
f"insert into `welcome_group` (`group_id` , `qq_id`, `sum`, `datetime`) values ({group_id}, {qq_id},{sum},{date_time})"
1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '13:45:37)' at line 1"
修改后:
f"insert into `welcome_group` (`group_id` , `qq_id`, `sum`, `datetime`) values ({group_id}, {qq_id},{sum},'{date_time}')"
给这个时间相关的字段额外再加一个单引号就可以了。语句用双引号,有问题的字段用单引号。具体什么原理我没搞明白。