
我有以下简化示例:@H_403_2@
CREATE table pipelines ( name VARCHAR NOT NulL,owner VARCHAR NOT NulL,description VARCHAR,PRIMARY KEY (name,owner),FOREIGN KEY(owner) REFERENCES user (ID) ); CREATE table tasks ( ID INTEGER NOT NulL,Title VARCHAR,pipeline VARCHAR,owner VARCHAR,PRIMARY KEY (ID),FOREIGN KEY(pipeline) REFERENCES pipelines (name),FOREIGN KEY(owner) REFERENCES pipelines (owner) ); CREATE table user ( ID VARCHAR NOT NulL,name VARCHAR,password VARCHAR,PRIMARY KEY (ID) ); pragma foreign_keys=on; insert into user values ('wayne','',''); insert into pipelines values ('pipey','wayne',''); insert into tasks values (1,'hello','pipey','wayne'); 执行此代码时,它会失败:@H_403_2@
$sqlite3 foo.sq3 '.read mismatch.sql' Error: near line 27: foreign key mismatch
通过我引用的问题列表:@H_403_2@
>父表(用户)存在.
>存在父列(名称,所有者)
>父列实际上是主键(我原以为可能是原来的)
>子表引用父表中的所有主键列@H_403_2@
那么世界上可能会导致这个错误呢?@H_403_2@ documentation说:
Usually,the parent key of a foreign key constraint is the primary key of the parent table. If they are not the primary key,then the parent key columns must be collectively subject to a UNIQUE constraint or have a UNIQUE index.@H_403_2@
在管道表中,名称和所有者列本身都不是唯一的.@H_403_2@
我猜你真的想在tasks表中有一个两列的外键:@H_403_2@
FOREIGN KEY(pipeline,owner) REFERENCES pipelines(name,owner)总结
以上是内存溢出为你收集整理的是什么导致这个sqlite外键不匹配?全部内容,希望文章能够帮你解决是什么导致这个sqlite外键不匹配?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)