我正在觀看 Udacity 課程中的視頻,并在嘗試通過 psycopg2 運(yùn)行 SQL 命令時(shí)遇到錯(cuò)誤。該代碼與講師的相同,但我的返回錯(cuò)誤而她的沒有。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()錯(cuò)誤:$ 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貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊
你似乎打錯(cuò)了而不是DEFAULT你寫的DEFUALT
cursor.execute('''
CREATE TABLE table2 (
id INTEGER PRIMARY KEY,
completed BOOLEAN NOT NULL DEFAULT False
);
''')
添加回答
舉報(bào)
0/150
提交
取消