Python 警告:(1265,“第1行日期和列的数据被截断”)

Python 警告:(1265,“第1行日期和列的数据被截断”),python,mysql,python-3.x,date,warnings,Python,Mysql,Python 3.x,Date,Warnings,我使用python3在mysql数据库中插入一些值。我需要输入一个名称,后跟三列数字(大约15位数字),然后是另一列,其中有日期 下面是我的python代码 today = datetime.date.today() datestr = str(today.month)+"/"+str(today.day)+"/"+str(today.year) connection = pymysql.connect(host='localhost', user='root', password='', d

我使用python3在mysql数据库中插入一些值。我需要输入一个名称,后跟三列数字(大约15位数字),然后是另一列,其中有日期

下面是我的python代码

today = datetime.date.today()
datestr = str(today.month)+"/"+str(today.day)+"/"+str(today.year)

connection = pymysql.connect(host='localhost', user='root', password='', db='testdb')

for item in resp['result']:
    data = (item['name'], item['numberone'], item['numbertwo'], item['numberthree'], item['numberfour'], datestr)
    cursor = connection.cursor()
    sql = ('INSERT INTO testdb.testtable (`Name`, `Col1`, `Col2`, `Col3`, `Col4`, `Date`) VALUES (%s, %s, %s, %s, %s, %s)')
    cursor.execute(sql, data)


connection.close()
但是我得到了下面的错误

Python36\lib\site-packages\pymysql\cursors.py:165: Warning: (1265, "Data truncated for column 'Date' at row 1")
result = self._query(query)
[Finished in 0.7s]
如果我在循环中打印变量数据。我得到下面的输出。这只是向您展示我试图插入到表中的数据类型

('Myname', 169324790808576, 167102568398848, 2222222409728, 2222222409728, '4/30/2018')

我想在mysql数据库中插入所有这些值,包括日期。我得到了日期的错误信息。感谢您帮助解决此问题

MySQL遵循这些常规日期格式yyyy-mm-dd或yyyy/mm/dd,而不是mm/dd/yyyy,假设日期列是日期数据类型。。小演示完美!。你是对的。这修正了错误。非常感谢!:)@还有一个小的后续问题。现在代码似乎运行时没有任何错误。但是,我仍然看不到通过Insert命令将日期输入数据库。你知道原因是什么吗。上面的代码没有变化。只是根据您之前的评论更改了日期顺序。@RaymondNijland无需担心。我自己纠正了这个错误。我错过了connection.commit()函数,该函数必须写在for循环的末尾,用于将值更新到数据库中。无论如何,谢谢!:)