Shortened, essential code, for reference:
def sqlInput(groupValues, userLogin):
sqliteConnection = None
try:
sqliteConnection = sqlite3.connect( NEA.db )
cursor = sqliteConnection.cursor()
print()
print("Connected to SQLite server.")
print()
cursor.execute( CREATE TABLE IF NOT EXISTS "Food Tracker" (
ID INTEGER PRIMARY KEY,
"Entry Number" INTEGER,
"Calories" INTEGER,
"Food Item" TEXT,
"Date" TEXT,
"Time" TEXT
) )
insertQuery ="""INSERT INTO Food Tracker(
"ID", "Food Item", "Calories", "Date", Time)
VALUES
(?,?,?,?,?,?)"""
inserting = list(
zip(userLogin.primarykey, groupValues.entry, groupValues.food, map(int, groupValues.calories), groupValues.date, groupValues.time))
cursor.executemany(insertQuery,inserting)
sqliteConnection.commit()
print("Successfully entered data into SQLite database.")
print()
menu(userLogin)
except sqlite3.Error as error:
print()
print("Failed to insert data into SQLite database:", error)
print()
finally:
if sqliteConnection:
sqliteConnection.close()
在这方面,我正在奋起努力。
insertQuery ="""INSERT INTO Food Tracker(
ID, Food Item, Calories, Date, Time)
VALUES
(?,?,?,?,?)"""
inserting = list(
zip(userLogin.primarykey, groupValues.entry, groupValues.food, map(int, groupValues.calories), groupValues.date, groupValues.time))
Everything inserts fine into the database. No problems with anything apart from the ID column. It won t display as my ID, which is stored in userInput.primarykey
(no errors with that either), and instead of ID being "62381" for example which is a valid example ID, it will display as "1" and increment with every entry added.
How do I get my ID to stay as 62381 for example within userInput.primarykey and not increment?
我曾尝试增加一个精良的外国钥匙,我曾尝试改变母体的次序,并使用其他指挥,如MAP & ZIP。
Nothing works, AI won t provide an answer, I really need a solution. Any further information needed, let me know although I believe I ve added everything you d need.
请帮助我解决这一问题,因为我已有很多问题被搁置,但这是有效的,我需要迅速的解决办法。
Error message: Failed to retrieve last entry number: UNIQUE constraint failed: Food Tracker.ID How can I use the primary key multiple times?