2017-03-02 65 views
-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)); 

我得到這個錯誤消息2個值:如何修復錯誤:5列

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 
+0

您確定這個代碼實際執行嗎?在'execute'行之前嘗試'print(insert_to_students,new_student_info)'。 –

回答

0

我覺得這樣的事情可能工作: cursor.execute(「INSERT INTO學生VALUES (?,?,?,?,?)',(ID,first_name,surname,year_group,strike))