I have created a table named 'Issue' with Issue_serial_number as AUTOINCREMENT-
sql= '''
CREATE TABLE Issue(
Issue_serial_no INTEGER AUTO INCREMENT,
roll_no INTEGER,
Book_ID INTEGER,
Issue_Date DATE,
FOREIGN KEY (roll_no) REFERENCES Student(roll_no),
FOREIGN KEY (Book_ID) REFERENCES Book(Book_ID)
);
'''
try:
connection.execute(sql)
print("Issue table is being created")
except:
print("issue table not created")
Now when I am running the following-
import datetime
c=connection.cursor()
now=datetime.date(2012,5,5)
c.execute("INSERT INTO Issue (roll_no, Book_ID, Issue_Date) VALUES(?,?,?)",(n,bi,now))
p=connection.cursor()
p.execute("select * from Issue")
for row in p.fetchall():
print('Issue_serial_no: '+str(row[0]) + ' roll_no: '+ str(row[1])+ ' Book_ID: '+ str(row[2])+ ' Issue_Date: '+ str(row[3]))
Issue serial number is coming as None- Issue_serial_no: None roll_no: 3 Book_ID: 1 Issue_Date: 2012-05-05
How AUTOINCREMENT will be implemented?