SQLite Abort due to constraint violation

access_time 12 years ago visibility685 comment 0

今天自己使用SQlite数据库的时候创建了一个表 大致是:

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数据库的数据类型还不是特别熟悉以至于导致了这个错误,浪费了很多时间


info Last modified by Raymond at 6 months ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Want to publish your article on Kontext?

Learn more

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.


Learn more arrow_forward

More from Kontext

local_offer python local_offer sqlite local_offer python-database

visibility 99
thumb_up 0
access_time 6 months ago

SQLite is one of the most commonly used embedded file databases. All the mainstream programming language/framework provides APIs to interact with SQLite database. In my previous article  SQLite in .NET Core with Entity Framework Core , code snippet is provided to interact with SQLite via ...

local_offer sqlite local_offer entity-framework local_offer dotnetcore

visibility 28531
thumb_up 2
access_time 3 years ago

SQLite is a self-contained and embedded SQL database engine. In .NET Core, Entity Framework Core provides APIs to work with SQLite. This page provides sample code to create a SQLite database using package Microsoft.EntityFrameworkCore.Sqlite . Create a .NET Core 2.x console application in ...

local_offer pandas local_offer sqlite local_offer python-database

visibility 1162
thumb_up 0
access_time 6 months ago

In my previous posts, I showed how to use  jaydebeapi or sqlite3 packages to read data from SQLite databases. The high level approach I followed are: Create database connection Create a cursor object via executing SQL SELECT command. Fetch all the records via the cursor Convert the ...

About column