SQL 命令上的 SynaxError

我正在观看 Udacity 课程中的视频,并在尝试通过 psycopg2 运行 SQL 命令时遇到错误。该代码与讲师的相同,但我的返回错误而她的没有。


import psycopg2


# establish connection to db

connection = psycopg2.connect('dbname=example')


# cursor is essentially an interface that allows you to start

# cuing up work and transactions

cursor = connection.cursor()


# defines SQL transaction

cursor.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 transaction

connection.commit()


# must manually close your session each time one is opened

connection.close()

cursor.close()

错误:


$ python3 demo.py

Traceback (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


白板的微信
浏览 87回答 1
1回答

慕尼黑的夜晚无繁华

你似乎打错了而不是DEFAULT你写的DEFUALTcursor.execute('''&nbsp; &nbsp; CREATE TABLE table2 (&nbsp; &nbsp; &nbsp; &nbsp; id INTEGER PRIMARY KEY,&nbsp; &nbsp; &nbsp; &nbsp; completed BOOLEAN NOT NULL DEFAULT False&nbsp; &nbsp; );''')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python