Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为加载数据匹配python中的mysql数据类型_Python_Mysql - Fatal编程技术网

为加载数据匹配python中的mysql数据类型

为加载数据匹配python中的mysql数据类型,python,mysql,Python,Mysql,我有一个python脚本将数据加载到mysql表,我遇到的问题如下: Warning: Incorrect integer value: 'user_id' for column 'user_id' at row 1 +'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',row) Warning: Invalid TIMESTAMP value in column 'edit_time' at row 1 +'VALUES (%s,

我有一个python脚本将数据加载到mysql表,我遇到的问题如下:

Warning: Incorrect integer value: 'user_id' for column 'user_id' at row 1
  +'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',row)
Warning: Invalid TIMESTAMP value in column 'edit_time' at row 1
  +'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',row)
这只是许多警告行中的一行,我理解错误,根据我的理解,我猜行仍然是字符串格式,或者转换没有正确进行。在我从tsv文件中读取元素后,我正在考虑对行中的每个元素进行强制转换

example: int(row[0])
但我不确定如何正确地强制转换以匹配相关时间戳元素的MySQL时间戳类型

#load training data
def readtsv(file_name, con):
    cur = con.cursor()
    with open('file.tsv', 'rb') as f:
        for row in csv.reader(f, delimiter='\t'):
            cur.execute('INSERT INTO mytable(user_id, article_id, revision_id, namespace, edit_time, md5, reverted, reverted_user_id, reverted_revision_id, delta, cur_size)'
                        +'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',row)
    try:
        con.commit()
    except Exception, e:
        print 'unable to commit'
        print e

您是否检查了时间戳值是否正确

如果是这样,MySQL将不会看到错误,因此不存在警告

作为提示,只需打印insert语句字符串,并尝试通过“PhpMyAdmin”或其他数据库接口工具启动它


MySQL的时间戳值的格式为:“YYYYMMDDHHMMSS”,因此今天2012年12月4日21:06:00将以这种方式写入:“20121204210600”,并加引号

我们应该看看你不正确的时间戳是如何格式化的,否则我们帮不了你