【问题标题】:sqlite3.OperationalError: table card_data has 11 columns but 10 values were suppliedsqlite3.OperationalError:表 card_data 有 11 列,但提供了 10 个值
【发布时间】:2012-07-23 18:42:14
【问题描述】:

我尝试在 Apache2 上遵循 python 脚本, 但我失败了。 根据/var/log/apache2/error.log, “sqlite3.OperationalError: 表 card_data 有 11 列,但提供了 10 个值”。

我不明白为什么 card_data 表有 11 列。 应该是 10 列。

我也试过 con.execute("PRAGMA table_info(card_data)") 但 card_data 有 10 列。

我想知道为什么 card_data 有 11 列以及如何解决这个问题。 谢谢。

    #!/usr/bin/python
    # -*- coding: utf-8 -*-

    import cgi
    import sqlite3

    f = cgi.FieldStorage()
    cardname = unicode(f.getfirst("cardname", "default string"), 'utf-8')
    cardtype = unicode(f.getfirst("cardtype", "default string"), 'utf-8')
    cost = unicode(f.getfirst("cost", "default string"), 'utf-8')
    color = unicode(f.getfirst("color", "default string"), 'utf-8')
    text = unicode(f.getfirst("text", "default string"), 'utf-8')
    igflag = unicode(f.getfirst("igflag", "default string"), 'utf-8')
    tribe = unicode(f.getfirst("tribe", "default string"), 'utf-8')
    power = unicode(f.getfirst("power", "default string"), 'utf-8')
    cardid = unicode(f.getfirst("cardid", "default string"), 'utf-8')
    dispname = unicode(f.getfirst("displayname", cardname), 'utf-8')

    conn = sqlite3.connect("carddata.db")

    sql = u"""create table if not exists card_data(
        NAME TEXT,
        TYPE TEXT,
        COST, INTEGER,
        COLOR TEXT,
        CRADTEXT TEXT,
        IGNITION NULL,
        TRIBE TEXT,
        POWER INTEGER,
        CARDID TEXT,
        DISPLAY TEXT);
    """
    conn.execute(sql)
    conn.commit()

    sql = u"insert into card_data values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
    conn.execute(sql, (cardname, cardtype, int(cost), color, text, igflag, tribe, int(power), cardid, dispname))
    conn.commit()

【问题讨论】:

    标签: sqlite python-2.7


    【解决方案1】:

    这一行

    COST, INTEGER,
    

    创建两个列。

    【讨论】:

    • 感谢您的帮助,但不知何故,同样的错误仍然存​​在。
    • 也许您应该在 Python 之外仅使用 sqlite3 工具检查您的 SQL。
    猜你喜欢
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多