csvkit mysql导入失败,并出现VARCHAR,要求方言mysql具有一定长度

时间:2019-02-22 09:28:25

标签: mysql csvkit pymsql

使用以下命令安装csvkit之后

$ sudo -HE pip install --upgrade -e git+git://github.com/wireservice/csvkit.git@master#egg=csvkit

,并尝试如下导入.csv

csvsql --db mysql://root:root@127.0.0.1:3306/jira_test --insert --table bugs_temp --no-constraints --overwrite --create-if-not-exists --no-inference --blanks bugs_temp.csv

我遇到以下错误

/usr/local/lib/python2.7/dist-packages/agate/utils.py:292: DuplicateColumnWarning: Column name "0" already exists in Table. Column will be renamed to "0_2".
/usr/local/lib/python2.7/dist-packages/agate/utils.py:292: DuplicateColumnWarning: Column name "0" already exists in Table. Column will be renamed to "0_3".
/usr/local/lib/python2.7/dist-packages/agate/utils.py:292: DuplicateColumnWarning: Column name "0" already exists in Table. Column will be renamed to "0_4".
/usr/local/lib/python2.7/dist-packages/agate/utils.py:292: DuplicateColumnWarning: Column name "0" already exists in Table. Column will be renamed to "0_5".
/usr/local/lib/python2.7/dist-packages/agate/utils.py:292: DuplicateColumnWarning: Column name "0" already exists in Table. Column will be renamed to "0_6".
/usr/local/lib/python2.7/dist-packages/agate/utils.py:292: DuplicateColumnWarning: Column name "0" already exists in Table. Column will be renamed to "0_7".
/usr/local/lib/python2.7/dist-packages/agate/utils.py:292: DuplicateColumnWarning: Column name "0" already exists in Table. Column will be renamed to "0_8".
/usr/local/lib/python2.7/dist-packages/agate/utils.py:292: DuplicateColumnWarning: Column name "0" already exists in Table. Column will be renamed to "0_9".
(in table 'bugs_temp', column 'ESS-3146'): VARCHAR requires a length on dialect mysql

1 个答案:

答案 0 :(得分:0)

(此答案可能有些不完整。我没有使用csvsql的经验,因此我将其作为Wiki。)

depends上的csvkit agate-sqldepends上的sqlalchemy

sqlalchemy包含this line of code

    "VARCHAR requires a length on dialect %s" % self.dialect.name

似乎“ 您需要为所有字符串指定长度”,并引用this answer

这意味着您不能使用--no-constraints选项:

  --no-constraints      Generate a schema without length limits or null
                        checks. Useful when sampling big tables.

请参见https://csvkit.readthedocs.io/en/latest/scripts/csvsql.html