Raymond Raymond

SQLite Abort due to constraint violation

event 2009-03-15 visibility 1,032 comment 0 insights
more_vert
insights Stats

今天自己使用SQlite数据库的时候创建了一个表,DDL如下:

Create  TABLE [Logs](
[LogID] int PRIMARY KEY NOT NULL
,[LogTitle] varchar(100)
,[LogContent] text
,[LogType] int NOT NULL DEFAULT 0
,[LogAddTime] datetime
  );

然后在插入数据库的时候,要么是主键LogID同时为0要么是不能插入数据,错误信息大致是:

Abort due to constraint violation ... maybe not be null

于是自己就在思想因为我是想把主键设置成autoincrement,所以才设置的不能为空,这在SQl Server数据库中是正确的。在网上找了很久也没找到好的答案。自己想起了bbsmax,看了下她的sqlite数据库的设计,原来所有整型的地方都是用的integer,这个和Access有点类似,结果尝试了下,果然是这个原因....

Create  TABLE [Logs](
[LogID] integer PRIMARY KEY NOT NULL
,[LogTitle] varchar(100)
,[LogContent] text
,[LogType] int NOT NULL DEFAULT 0
,[LogAddTime] datetime
  );

总结:自己对sqlite数据库的数据类型还不是特别熟悉以至于导致了这个错误,浪费了很多时间。

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts