我正在观看 Udacity 课程中的视频,并在尝试通过 psycopg2 运行 SQL 命令时遇到错误。该代码与讲师的相同,但我的返回错误而她的没有。import psycopg2# establish connection to dbconnection = psycopg2.connect('dbname=example')# cursor is essentially an interface that allows you to start# cuing up work and transactionscursor = connection.cursor()# defines SQL transactioncursor.execute(''' CREATE TABLE table2 ( id INTEGER PRIMARY KEY, completed BOOLEAN NOT NULL DEFUALT False );''')cursor.execute('INSERT INTO table2 (id, completed) VALUES (1, true);')# commits the transactionconnection.commit()# must manually close your session each time one is openedconnection.close()cursor.close()错误:$ python3 demo.pyTraceback (most recent call last): File "demo.py", line 11, in <module> cursor.execute("""psycopg2.errors.SyntaxError: syntax error at or near "DEFUALT"LINE 4: completed BOOLEAN NOT NULL DEFUALT False
1 回答
慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
你似乎打错了而不是DEFAULT你写的DEFUALT
cursor.execute('''
CREATE TABLE table2 (
id INTEGER PRIMARY KEY,
completed BOOLEAN NOT NULL DEFAULT False
);
''')
添加回答
举报
0/150
提交
取消