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

时间:2017-03-02 12:32:49

标签: python sqlite

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:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "M:\computer science a2\comp 3\login.py", line 59, in add_student
cursor.execute(insert_to_students, new_student_info)
sqlite3.OperationalError: 2 values for 5 columns

1 个答案:

答案 0 :(得分:0)

我觉得这样的事情可能有用: cursor.execute('INSERT INTO students VALUES(?,?,?,?,?)',(ID,first_name,surname,year_group,strike))