dimanche 13 décembre 2015

How to insert row with an auto increment column SQLite

I downloded a MySQL database and parse it to SQLite using this PHP script.

I use the SQLite database on WPF and i am able to make some operations using this library. The problem is that i tried to execute an INSERT in a table with an auto increment field and it is not working, here is my query:

SQLiteConnection conn = new SQLiteConnection("Data Source=test.db");
conn.Open();
var command = conn.CreateCommand();

command.CommandText = "INSERT INTO tickets(created, user) values ('2015-12-12', 345)";
command.ExecuteNonQuery();
conn.Close();

Here is my table tickets at the .db:

CREATE TABLE "tickets" (
  "id" int(11) NOT NULL ,
  "user" int(11) NOT NULL,
  "created" timestamp NOT NULL ,
  PRIMARY KEY ("id")
)

At MySQL my query works perfect and my id column always get the next auto increment value, but in SQLite i can't get this value to autoincrement. When i run the app it crashes with the next message:

Additional information: constraint failed

NOT NULL constraint failed: tickets.id

I know the value should not be null, but it should be auto incrementing... is this possible?

Aucun commentaire:

Enregistrer un commentaire