Search code examples
databasesqlitesyntax-errorauto-incrementparse-error

Parse error: near "autoincrement": syntax error - SQLite


I get a syntax error near AUTOINCREMENT. What is the cause of this error?

CREATE TABLE person (
    id INTEGER NOT NULL AUTOINCREMENT,
    name TEXT NOT NULL
);

CREATE TABLE department (
    id INTEGER NOT NULL AUTOINCREMENT,
    name TEXT NOT NULL,
    FOREIGN KEY (leader) REFERENCES person(id)
);

Solution

  • According to SQLite FAQ you have to declare either a INTEGER PRIMARY KEY or INTEGER PRIMARY KEY AUTOINCREMENT column to achieve that.