0

In short, i have this clause:

CREATE TABLE IF NOT EXISTS `journalData` 
(
    `JD_Key` INTEGER PRIMARY KEY AUTOINCREMENT, 
    `JD_Event_Key` INTEGER, 
    `JD_VarCount` INTEGER, 
    `JD_VarTypes` TEXT, 
    `JD_VarValues` TEXT,
    `JD_EventDate` TEXT 
);

INSERT INTO `journalData` 
VALUES (24, 0, '', '', '04.02.2023 20:26:18'); 

And following SQLite tutorials on AUTOINCREMENT (https://www.sqlitetutorial.net/sqlite-autoincrement/), it says the following:

Second, insert another row without specifying a value for the person_id column:

INSERT INTO people (first_name,last_name)
VALUES('William','Gate');

Implying, that you can add rows to the table, without having to specify primary key of a table, but I get this error:

Uncaught Error: table journalData has 6 columns but 5 values were supplied

What am I doing here wrong? I've tried to add single row with the key before mentioned insert. But I keep getting this error

1 Answer 1

1

I found a solution, it seems that error was somewhat misleading, i have to specify columns names.

though, if i specify all of the values in table it is not necessary to specify columns names, so because of that, during testing i assumed that syntax here is similar to MySQL, where from experience i remembered, that you don't have to specify names in this exact case.

so the following query worked for me.

INSERT INTO `journalData` 
(JD_Event_Key, JD_VarCount, JD_VarTypes, JD_VarValues, JD_Event_Date) 
VALUES (24,0,'','','04.02.2023 20:26:18');
Sign up to request clarification or add additional context in comments.

2 Comments

Always explicitly specifying the columns in the INSERT INTO clause is a recommended and well established best practice anyway - just get used to it and you won't even look back...
@marc_s, seems fair

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.