I got the same error below:
Parse error: near "autoincrement": syntax error
Because I used AUTOINCREMENT
without INTEGER PRIMARY KEY
as shown below:
CREATE TABLE my_table (
id INTEGER AUTOINCREMENT
-- ↑↑↑↑↑↑↑↑↑↑↑↑↑
);
So, I used AUTOINCREMENT
with INTEGER PRIMARY KEY
as shown below, then the error was solved:
CREATE TABLE my_table (
id INTEGER PRIMARY KEY AUTOINCREMENT
-- ↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑ ↑↑↑
);
The doc says below:
Any attempt to use AUTOINCREMENT
on a WITHOUT ROWID table or on a column other than the INTEGER PRIMARY KEY
column results in an error.
In addition, if you use TEXT
type with PRIMARY KEY AUTOINCREMENT
as shown below:
CREATE TABLE my_table (
id TEXT PRIMARY KEY AUTOINCREMENT
-- ↑↑↑↑
);
Then, you get the error below:
Parse error: AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY
select rowid, * from table_name
to retrieve the rowid as well. – Equator