是什么导致这个sqlite外键不匹配?

前端之家收集整理的这篇文章主要介绍了是什么导致这个sqlite外键不匹配?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经检查了 this question,并且认为我得到了答案 – 但那时我看起来并不合适. @H_301_1@我有以下简化示例:

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_301_1@执行此代码时,它会失败:

$sqlite3 foo.sq3 '.read mismatch.sql'    
Error: near line 27: foreign key mismatch
@H_301_1@通过我引用的问题列表:

@H_301_1@>父表(用户)存在.
>存在父列(名称,所有者)
>父列实际上是主键(我原以为可能是原来的)
>子表引用父表中的所有主键列

@H_301_1@那么世界上可能会导致这个错误呢?

documentation说:
@H_301_1@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_301_1@在管道表中,名称和所有者列本身都不是唯一的.

@H_301_1@我猜你真的想在tasks表中有一个两列的外键:

FOREIGN KEY(pipeline,owner) REFERENCES pipelines(name,owner)
原文链接:https://www.f2er.com/sqlite/238922.html

猜你在找的Sqlite相关文章