Answer the question
In order to leave comments, you need to log in
How to add autoincrement to a column in SQLite3 database?
def add():
kind1 = kind_Entry.get()
species1 = species_Entry.get()
birth1 = birth_Entry.get()
weight1 = weight_Entry.get()
cursor.execute("INSERT INTO animal (kind, species, birth_day, weight) VALUES (?, ?, ?, ?)", (kind1, species1,
birth1, weight1))
db.commit()
cursor.execute("SELECT * FROM animal;")
db.commit()
note.destroy()
with sqlite3.connect('D:\Education\practice.db') as db:
cursor = db.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS
animal(
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
kind TEXT,
species TEXT,
birth_day DATE,
weight INT)
""")
db.commit()
Answer the question
In order to leave comments, you need to log in
Try like this
DELETE FROM animal;
DELETE FROM sqlite_sequence WHERE name = 'animal';
cursor.execute("INSERT INTO animal (kind, species, birth_day, weight) VALUES (?, ?, ?, ?)", (kind1, species1, birth1, weight1))
you can write a trigger to add a new record to update the field you need by doing something like select max+1
ps for identifiers, this is bad practice, do not mix identification and sequence number, especially if data can be deleted as soon as you start referencing records from outside identifier, then you will start conflicts
pps and if you remove 'from the middle' of your sequence, and then add a new one, do you want to get a new value or an old one freed?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question