如何修复误差:5列的2个值


def add_student():
 with sqlite3.connect("BehaviourManagement.db") as db:
    cursor = db.cursor()
    ID = 1
    first_name = input("Enter student first name: ")
    surname = input("Enter student surname: ")
    year_group = int(input("Enter student year group: "))
    strike = 0
    new_student_info = (ID, first_name, surname, year_group, strike)
    cursor.execute(insert_to_students, new_student_info)
    db.commit()
    ID = ID + 1
CREATE TABLE students(
        ID INTEGER,
        first_name TEXT,
        Surname TEXT,
        year_group INTEGER,
        strike INTEGER,
        Primary Key(ID));

我收到此错误消息:

Exception in Tkinter callback
Traceback (most recent call last):  
File "C:Python33libtkinter__init__.py", line 1475, in __call__
return self.func(*args)
File "M:computer science a2comp 3login.py", line 59, in add_student
cursor.execute(insert_to_students, new_student_info)
sqlite3.OperationalError: 2 values for 5 columns

我认为这样的事情可能有效:cursor.execute('插入学生值(?,?,?,?,?)',(id,first_name,surname,year_group,strike))

最新更新