By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .
access_time 12 years ago visibility643 comment 0 language中文

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

More from Kontext

visibility 13649
thumb_up 0
access_time 6 years ago

SQL Server Compact 4.0 (CE 4.0) is a free SQL Server embedded database ideal for building standalone and occasionally connected applications for mobile devices, desktops, Web clients and others. In one of my projects, I used it as the database for logging errors, which assumes the errors will onl...

open_in_new View open_in_new SQL Server

visibility 684
thumb_up 0
access_time 6 years ago

SQL Server provides a batch of great features to build robust, high-performance and scalable data solutions. ...

open_in_new View open_in_new SQL Server

visibility 1143
thumb_up 0
access_time 6 years ago

Serial: An Introduction to SQL Server Features Case Scenario In the previous articles of this serial, I’ve introduced how to use SQL Server as database for online transaction proces...

open_in_new View open_in_new SQL Server

visibility 4114
thumb_up 0
access_time 6 years ago

Serial: An Introduction to SQL Server Features Case Scenario For this ETL project, the requirements are listed below: Sales data will be pushed to specified shared fold...

open_in_new View open_in_new SQL Server

info About author

Kontext dark theme mode

Dark theme mode

Dark theme mode is available on Kontext.

Learn more arrow_forward
Kontext Column

Kontext Column

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

Learn more arrow_forward
info Follow us on Twitter to get the latest article updates. Follow us