sqlite3 “foreign key constraint failed”

后端 未结 2 1600
[愿得一人]
[愿得一人] 2021-01-03 23:25

I\'ve set up two tables:

CREATE TABLE A
(
    id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    name TEXT
 );

CREATE TABLE B
(
    id INTEGER NOT NULL PRIM         


        
2条回答
  •  被撕碎了的回忆
    2021-01-04 00:03

    The "problem" is that you have set a foreign key on table B.

    foreign key(id2) references A(id)
    

    This means that column id2 in table B references column id in table A. Both Lord of the Rings and Catch 22 from Table B are linked to John from Table A. Therefore you cannot delete John without first deleting these other two entries from Table B first.

    The alternative would be to remove the foreign key.

    See this documentation for more details.

提交回复
热议问题