3

I am trying to insert values in a table in SQLite but getting

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

I am unable to find any of the errors. Can someone help to figure the error out?

Here is my create table statement:

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

and here is my insert statement.

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

1 Answer 1

1

First of all: ALWAYS SPECIFY COLUMN LIST

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

Second make it easier to read and debug by using formatting:

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

You could easily spot your bug that way or simply comment lines until it works.

DBFiddle Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. i have got my error. and thanks for your suggestion. i will follow if from now.Thanks a lot...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.