Aug-14-2020, 03:56 PM
I'm trying to make a table in a SQLite3 database using the following code:
Thanks
import sqlite3 # imports the SQLite library with sqlite3.connect("Bookinfo.db") as db: # creates Bookinfo database cursor = db.cursor() cursor.execute("""CREATE TABLE IF NOT EXISTS Authors(Name text PRIMARY KEY, Place of Birth text NOT NULL);""") # creates the Authors table with Name and PoB as fields cursor.execute("""INSERT INTO Authors(Name, PlaceofBirth) VALUES("Agatha Christie","Torquay")""") # adds this entry into the table db.commit() # this line saves the changes cursor.execute("""INSERT INTO Authors(Name, PlaceofBirth) VALUES("Cecelia Ahern","Dublin")""") # adds this entry into the table db.commit() # this line saves the changes cursor.execute("""INSERT INTO Authors(Name, PlaceofBirth) VALUES("J.K. Rowling","Bristol")""") # adds this entry into the table db.commit() # this line saves the changes cursor.execute("""INSERT INTO Authors(Name,PlaceofBirth) VALUES("Oscar Wilde","Dublin")""") # adds this entry into the table db.commit() # this line saves the changesbut I keep getting the following error:
Error:Traceback (most recent call last):
File "c:/Users/djwil/Documents/python/learning python/Chapter 18 - SQLite/Ch18-c3.py", line 9, in <module>
cursor.execute("""INSERT INTO Authors(Name, PlaceofBirth)
sqlite3.IntegrityError: UNIQUE constraint failed: Authors.Name
However all my Name entries are different so I'm unsure as to why I'm getting this error. Can someone help?Thanks