今天自己使用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 3 months ago * This page is subject to Site terms.

More from Kontext

local_offer pandas local_offer sqlite

visibility 115
thumb_up 0
access_time 3 months ago

In my previous posts, I showed how to use  jaydebeapi or sqlite3 pack...

open_in_new Python Programming

local_offer sqlite local_offer python local_offer Java

visibility 85
thumb_up 0
access_time 3 months ago

To read data from SQLite database in Python, you can use the built-in sqlite3 package . Another approach is to use SQLite JDBC driver via  ...

open_in_new Python Programming

local_offer python local_offer sqlite

visibility 38
thumb_up 0
access_time 3 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  ...

open_in_new Python Programming

local_offer sqlite local_offer .net core local_offer entity-framework

visibility 22873
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 sample project ...

open_in_new .NET Framework

info About author

comment Comments (0)

comment Add comment

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

No comments yet.

Dark theme mode

Dark theme mode is available on Kontext.

Learn more arrow_forward

Kontext Column

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


Learn more arrow_forward