我有两张桌子,还有一张外键。虽然我已定义条件ON DELETE
和ON UPDATE
,但当我从BENEFIT
表中删除一行时,我会得到一个integrity error
。
错误记录如下:
psycopg2.IntegrityError
psycopg2.IntegrityError:在表格上更新或删除"好处"违反外键约束" people_hasbenefit_fkey"在桌子上"人们"
详细信息:关键(受益)=(提高智力)仍然从表格#34;人员"中提及。
表格如下:
"""CREATE TABLE IF NOT EXISTS benefit (
ID serial PRIMARY KEY,
Benef text UNIQUE NOT NULL,
Type text NOT NULL)"""
"""CREATE TABLE IF NOT EXISTS people (
Peopleid serial PRIMARY KEY,
Name text NOT NULL,
HasBenefit text references benefit(Benef)
ON DELETE SET NULL
ON UPDATE SET NULL )"""