2017-08-29 2 views
2

Je suis en train d'insérer des valeurs dans une table SQLite mais seSqLite.js Uncaught Erreur: contrainte CHECK échoué

SqLite.js Uncaught Error: CHECK constraint failed: st .

Je suis incapable de trouver des erreurs. Quelqu'un peut-il aider à comprendre l'erreur?

Voici mon instruction create table:

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) 
); 

et voici ma déclaration d'insertion.

insert into st values('a1','jamshaid','iqbal',1110332507339,julianday('1998- 
10-05'),'26 eb rehmkot','a1','a1','Admin'); 

Répondre

1

tout d'abord: TOUJOURS PRÉCISER COLONNE LISTE

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'); 

deuxième rendent plus facile à lire et déboguer en utilisant la mise en forme:

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 
) 
); 

Vous pouvez facilement repérer votre bug de cette façon ou simplement commenter les lignes jusqu'à ce que cela fonctionne.

DBFiddle Demo

+1

Merci pour votre réponse. J'ai mon erreur. et merci pour votre suggestion. Je vais suivre si à partir de maintenant.Merci beaucoup ... –