Whilst creating an 'INSERT', I have included the "try and except" approach to alert the user to when a duplicate primary key is entered, using a message box. Nevertheless, when a duplicate key is entered, the next time the 'INSERT' is ran, it gives the following error:
"sqlite3.OperationalError: database is locked"
Is there is another approach to solving this issue at all?
I've added the 'INSERT' below to the post with the relevant table creation.
Insert Function
try: conn=sqlite3.connect("Homework_Planner.db") conn.execute("INSERT INTO Student (StudentID, Email, Password) \ VALUES (?,?,?);",(student_ID, student_Email, hashedPassword,)) conn.commit() #Commits changes made to the database. conn.close() #Closes the database.. except sqlite3.IntegrityError: messagebox.showinfo('Setup Error!', 'Student ID already exists.') x=windows() x.student_Setup() Table Creation
conn=sqlite3.connect("Homework_Planner.db") conn.execute (''' CREATE TABLE IF NOT EXISTS Student ( StudentID TEXT PRIMARY KEY NOT NULL, Email TEXT NOT NULL, Password TEXT NOT NULL );''')