删除级联上的递归外键'

时间:2015-04-07 23:07:12

标签: sqlite foreign-keys

CREATE TABLE IF NOT EXISTS type (
    tid INTEGER NOT NULL,
    uuid VARCHAR NOT NULL,
    name VARCHAR NOT NULL,
    CONSTRAINT PK PRIMARY KEY (tid),
    CONSTRAINT UNQ_0 UNIQUE (uuid),
    CONSTRAINT UNQ_1 UNIQUE (name)
);
CREATE INDEX IDX_type_0 ON type (tid,uuid,name);

CREATE TABLE IF NOT EXISTS object (
    oid VARCHAR NOT NULL,
    timestamp VARCHAR NOT NULL,
    tid INTEGER NOT NULL,
    CONSTRAINT FK_tid FOREIGN KEY (tid) REFERENCES type(tid) ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT UNQ_0 UNIQUE (oid)
);
CREATE INDEX IDX_object_0 ON object (oid,timestamp,tid);

CREATE TABLE IF NOT EXISTS object_user_owner (
    uid INTEGER NOT NULL,
    oid VARCHAR NOT NULL,
    CONSTRAINT FK_uid FOREIGN KEY (uid) REFERENCES user(uid) ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT FK_oid FOREIGN KEY (oid) REFERENCES object(oid) ON UPDATE CASCADE ON DELETE CASCADE,
    CONSTRAINT UNQ_0 UNIQUE (oid,uid)
);
CREATE INDEX IDX_object_user_owner_0 ON object_user_owner (uid,oid);

CREATE TABLE IF NOT EXISTS user (
    uid INTEGER NOT NULL,
    uuid VARCHAR NOT NULL,
    name VARCHAR NOT NULL,
    password VARCHAR NOT NULL,
    salt VARCHAR NOT NULL,
    timestamp VARCHAR NOT NULL,
    lastaccess VARCHAR NOT NULL,
    CONSTRAINT PK PRIMARY KEY (uid),
    CONSTRAINT UNQ_0 UNIQUE (uuid),
    CONSTRAINT UNQ_1 UNIQUE (name)
);
CREATE INDEX IDX_user_0 ON user (uid,uuid,name);

以上三个sqlite3表包含外键。问题是删除上表类型中的键。当我尝试删除时,我得到了'FOREIGN KEY约束失败'错误。删除类型之前从最低表object_user_owner中删除a工作。我认为sqlite不检查任何递归级联约束。有没有人经历过这个或者我的设计有什么问题?

0 个答案:

没有答案