这个 SQLite 语句中的错误是什么?

What is in the error in this SQLite statement?

我收到这个错误: SQL error (near "(": syntax error)

create table IF NOT EXISTS demo
(
    code varchar(200) default substr(lower(hex(randomblob(32))),1,6) not null primary key
);

我的代码有什么问题?

如果将 DEFAULT 与表达式而不是文字值一起使用,则必须将其括在括号中。

DEFAULT (substr(...))

来自the documentation

The DEFAULT clause specifies a default value to use for the column if no value is explicitly provided by the user when doing an INSERT. If there is no explicit DEFAULT clause attached to a column definition, then the default value of the column is NULL. An explicit DEFAULT clause may specify that the default value is NULL, a string constant, a blob constant, a signed-number, or any constant expression enclosed in parentheses. A default value may also be one of the special case-independent keywords CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP. For the purposes of the DEFAULT clause, an expression is considered constant if it contains no sub-queries, column or table references, bound parameters, or string literals enclosed in double-quotes instead of single-quotes.

在设置默认值之前尝试设置非空:

create table IF NOT EXISTS demo ( code varchar(200) primary key not null default substr(lower(hex(randomblob(32))),1,6)   );