2017-03-02 1 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 (ID, 이름, 성, 연도 그룹, 경고)