sqlite3-OperationalError表任务有3列,但提供了4个值

sqlite3-OperationalError表任务有3列,但提供了4个值,sqlite,python-3.8,Sqlite,Python 3.8,我在执行代码时遇到此错误: Exception has occurred: OperationalError table tasks has 3 columns but 4 values were supplied 以下是导致错误的代码片段: class Tasks: def __init__(self): self.conn = sqlite3.connect('tasks.db') self.cur = self.conn.cursor()

我在执行代码时遇到此错误:

Exception has occurred: OperationalError
table tasks has 3 columns but 4 values were supplied
以下是导致错误的代码片段:

class Tasks:
    def __init__(self):
        self.conn = sqlite3.connect('tasks.db')
        self.cur = self.conn.cursor()
    def connect(self):
        self.cur.execute("CREATE TABLE IF NOT EXISTS tasks (id INTEGER PRIMARY KEY, user_id integer, task text, date text)")
        self.conn.commit()
    def insert(self, user_id, task, date):
        self.cur.execute("INSERT INTO tasks VALUES(NULL, ?,?,?)", (user_id, task, date))#this line causes the error
        self.conn.commit()

tasks = Tasks()
tasks.insert(6, 'go out', '27.04.2021')

如何解决此问题?

可能是您创建了包含3列的表,然后添加了第4列。现在您正在使用
创建表(如果不存在…
),这不会影响表。删除表并重试。但是如何删除?在
connect()
方法中,我创建了一个包含4列的表。
如果不存在
如果表已经存在则什么也不做。仍然不工作。我删除了表,然后编译了相同的代码,现在我得到了以下错误:
编程错误提供的绑定数量不正确。当前语句使用3,提供了4个。