操作错误:接近“;(“语法错误”位于SQLite3
在参加SQLite3速成课程后,我尝试为我的第一个项目制作db:操作错误:接近“;(“语法错误”位于SQLite3,sqlite,Sqlite,在参加SQLite3速成课程后,我尝试为我的第一个项目制作db: import sqlite3 as db conn = db.connect('todo.db') cursor = conn.cursor() cursor.execute("CREATE TABLE todo(id serial primary key, title text, created timestamp default now(), done boolean default 'f')") cursor.exe
import sqlite3 as db
conn = db.connect('todo.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE todo(id serial primary key, title text, created
timestamp default now(), done boolean default 'f')")
cursor.execute("INSERT INTO todo (title) VALUES('Learn web.py')")
很遗憾,我收到了以下错误:
操作错误:在SQLite3的“(”:语法错误”附近
我不明白代码出了什么问题。有人能解释一下我做错了什么吗?如中所示,如果默认值不是简单的值,则必须用括号括起来:
CREATE TABLE todo(
...,
created timestamp default (now()),
done boolean default 'f'
);
(并且'f'
不是a的有效值,now()
不是SQLite函数。)