SqLite.js未捕获的错误:CHECK约束失败
问题描述:
我想在SQLite的一个表中插入值,但得到SqLite.js未捕获的错误:CHECK约束失败
SqLite.js Uncaught Error: CHECK constraint failed: st .
我无法找到任何错误的。有人可以帮助找出错误吗?
这里是我创建表的语句:
CREATE TABLE st(EMPLOYE_ID TEXT primary key , EMPLOYE_Name text NOT NULL ,
father_name text NOT NULL, cnic INTEGER NOT NULL,DOB real not null,address
text not null,
username text not null,password text not null, post text not null
CHECK(typeof(employe_id)='text' AND length(employe_id)<=10 and
(employe_name)='text' AND
length(employe_name)<=100 and (father_name)='text'
AND length(father_name)<=100 and(cnic)='integer' AND length(cnic)=13 and
(address)='text' and length(address)<=200
and (username)='text'
and length(username)<=10 and (password)='text' and length(password)<=20)
);
,这里是我的INSERT语句。
insert into st values('a1','jamshaid','iqbal',1110332507339,julianday('1998-
10-05'),'26 eb rehmkot','a1','a1','Admin');
答
首先:始终指定列列表
insert into st(employe_id, employe_name, father_name, cnic, DOB, address, username, password,post)
values('a1','jamshaid','iqbal',1110332507339,julianday('1998-10-05'),'26 eb rehmkot','a1','a1','Admin');
其次使其更易于阅读和调试使用格式:
CREATE TABLE st(
EMPLOYE_ID TEXT primary key , -- typo: employee_id, and why not INT
EMPLOYE_Name text NOT NULL ,
father_name text NOT NULL,
cnic INTEGER NOT NULL,
DOB real not null, -- why is DOB real and not DATE???
address text not null,
username text not null,
password text not null, -- I hope this is not clear text
post text not null
CHECK(
typeof(employe_id)='text'
AND length(employe_id)<=10
and typeof(employe_name)='text'
AND length(employe_name)<=100
and typeof(father_name)='text'
AND length(father_name)<=100
and typeof(cnic)='integer'
AND length(cnic)=13
and typeof(address)='text'
and length(address)<=200
and typeof(username)='text'
and length(username)<=10
and typeof(password)='text'
and length(password)<=20
)
);
你可以很容易地发现你的错误,或者直接注释行,直到它的工作。
感谢您的答复。我有我的错误。并感谢您的建议。如果从现在开始,我会跟进。谢谢很多... –