0

A similar question has been asked before, but the query is embedded in java and perhaps less clear to a total novice who would be asking this type of question.

I think the 'rowid' column is not auto-populating/auto-incrementing. Table, insert statement, and error code as follows:

CREATE TABLE T (rowid INTEGER PRIMARY KEY, c1 REAL, c2 REAL);

insert into T values (8,9);  

Error code in my DB Browser is:

table T has 3 columns but 2 values were supplied: insert into T values (1,2);

I have other code that is very similar but not producing this error. Any help is greatly appreciated! Thanks!!

Hanley Soilsmith
  • 579
  • 2
  • 9
  • 27

1 Answers1

0

This isn't a SQLite problem, it's a problem with your DB browser enforcing that values for all three columns must always be present.

One option to get around this would be to insert NULL for the rowid column. This should force SQLite to assign the next logical value, which is the behavior you want anyway:

INSERT INTO T values (NULL, 1, 2);
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Using AUTOINCREMENT doesn't change the error code. Also, the sqlite documentation says that it should AUTOINCREMENT a PRIMARY KEY automatically http://sqlite.org/autoinc.html thanks though! – Hanley Soilsmith Nov 23 '16 at 05:05
  • 1
    @HanleySoilsmith I believe this is a problem with your DB tool. Try inserting `NULL` for the `rowid`. – Tim Biegeleisen Nov 23 '16 at 05:27
  • I think this is the problem as well, however when I execute the query with python, my python shell gives the same error... going to look into updating sqlite3 and see if that works. For now, using null does work. Thank you for your help <3 – Hanley Soilsmith Nov 23 '16 at 06:13