【问题标题】:csvkit mysql import fails with VARCHAR requires a length on dialect mysqlcsvkit mysql导入失败,VARCHAR需要方言mysql的长度
【发布时间】:2019-07-16 08:38:33
【问题描述】:

使用以下命令安装 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

【问题讨论】:

    标签: mysql csvkit


    【解决方案1】:

    (这个答案可能有些不完整。我没有使用csvsql 的经验,所以我将其作为一个wiki。)

    csvkitdependsagate-sql,其中dependssqlalchemy。

    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

    【讨论】:

      猜你喜欢
      • 2010-12-30
      • 2013-02-15
      • 2011-12-17
      • 2012-08-14
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多