【发布时间】:2020-09-29 17:44:38
【问题描述】:
在使用 Python 3 和 SQLite3 时,在执行 cursor.execute("DELETE FROM my_table WHERE my_column IS NULL;") 时,出现错误
sqlite3.IntegrityError: FOREIGN KEY constraint failed
即使我在那之前做过connection.execute("PRAGMA foreign_keys = ON;")。不将foreign_keys 设置为ON 保证其他表中具有引用my_table 中已删除行的外键列的行也将被删除,从而防止此错误发生,或者我误解了该函数PRAGMA foreign_keys?
【问题讨论】:
标签: python sqlite foreign-keys