通过外键进行SQlite更新记录

时间:2018-03-11 18:04:07

标签: python sqlite sql-update foreign-keys

对于我的代码,我需要通过用户ID号更新记录。将值输入ExerciseWeight的输入框后,单击一个按钮即可更新记录。 Exercises是第一个具有外键ID的表,该外键与MemberID表中的memb相关联。我为此创建了一个UPDATE查询,这是代码:

    def Update(self):

    global MemberID

    connection = sqlite3.connect(r"E:\TESTING\Program\Accounts.db")

    cursor = connection.cursor()


    Exercise = self.Exercises.get()
    Weight = self.Weights.get()
    MemberID = self.ent_MemberID.get()

    List = [Exercise, Weight]


    cursor.execute("UPDATE Exercises SET Exercise=?, Weight=? WHERE ID = (SELECT MemberID FROM memb WHERE MemberID = ?);",(Exercise, Weight, MemberID))

    connection.commit()

它不会显示任何错误,但不会将数据输入表中。这是我用来创建Exercises表的代码:

CREATE TABLE `Exercises` (
`Exercise`  TEXT,
`Weight`    INTEGER,
`Reps`  INTEGER,
`Sets`  INTEGER,
`ID`    INTEGER,
PRIMARY KEY(`ID`),
FOREIGN KEY(`ID`) REFERENCES `memb`(`MemberID`)
);

0 个答案:

没有答案