Search code examples
sqliteios4appcelerator

SQLite: Constraint failed on Insert


I have one Auto Increment Field, rest are Integer,Text and Datetime field. How do I fix it out?

The Table Structure is given below:

CREATE TABLE "q1" (
     "sb_id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
     "sb_title" text(100,0) NOT NULL,
     "sb_details" text(300,0) NOT NULL,
     "sb_image" text(30,0) NOT NULL,
     "sb_type" integer(4,0) NOT NULL DEFAULT '1',
     "sb_date" datetime NOT NULL
)

Solution

  • It could be because in your insert command

    connection.execute("INSERT INTO q1(sb_title,sb_details)VALUES(?,?)",a,b);

    you didn't insert any values for sb_image or sb_date, both of which are NOT NULL and have no default defined. SQLite doesn't know what to put in there. You should either take away the NOT NULL constraint on those columns, define a default for the columns, or insert something explicitly.