sqlite3 – 当PRAGMA foreign_keys = ON时,是否允许在sqlite中使
发布时间:2020-12-12 18:53:33 所属栏目:百科 来源:网络整理
导读:根据 this,允许使用null外键,除非并且直到我们向模式添加适当的“NOT NULL”约束. 但我看到了一些不同的行为, sqlite PRAGMA Foreign_keys;1sqlite create table proc (pid integer,name text,ppid integer,foreign key (ppid) references proc (id));sqlite
根据
this,允许使用null外键,除非并且直到我们向模式添加适当的“NOT NULL”约束.
但我看到了一些不同的行为, sqlite> PRAGMA Foreign_keys; 1 sqlite> create table proc (pid integer,name text,ppid integer,foreign key (ppid) references proc (id)); sqlite> .schema proc CREATE TABLE proc (pid integer,foreign key (ppid) references proc (id)); sqlite> insert into proc (pid,name,ppid) values (0,"init",null); Error: foreign key mismatch sqlite> PRAGMA Foreign_keys=OFF; sqlite> PRAGMA Foreign_keys; 0 sqlite> insert into proc (pid,null) sqlite> select * from proc; 0|init| 当PRAGMA foreign_keys = ON时,如何在sqlite中允许空外键?或者根本不可能? 解决方法> ID列名为pid,而不是id. >父键列必须具有UNIQUE或PRIMARY KEY约束.(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |