Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)语法错误在或接近';用户'&引用;_Python_Sqlalchemy - Fatal编程技术网

Python sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)语法错误在或接近';用户'&引用;

Python sqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)语法错误在或接近';用户'&引用;,python,sqlalchemy,Python,Sqlalchemy,我正在尝试使用python/flask将新用户添加到现有的postgresql表中 输入似乎工作正常,但我在写入数据库时出错。我尝试了所有可能的括号安排,但没有成功 在登录中输入数据时,出现以下错误: sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) syntax error at or near "'user'" LINE 1: INSERT INTO 'user' (username, password) VALUES

我正在尝试使用python/flask将新用户添加到现有的postgresql表中 输入似乎工作正常,但我在写入数据库时出错。我尝试了所有可能的括号安排,但没有成功

在登录中输入数据时,出现以下错误:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) syntax error at or near "'user'"
LINE 1: INSERT INTO 'user' (username, password) VALUES ('joe', 'abcd...
                    ^
 [SQL: "INSERT INTO 'user' (username, password) VALUES ('joe', 'abcd')"] 
这是python代码:

@app.route("/register", methods=['GET', 'POST'])
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']

        reg = db.execute("INSERT INTO user (username, password) VALUES(':uname', ':pword')",
                        {"uname": username, "pword": password})
        print(reg)
        db.commit()
        return render_template('login.html')
    return render_template('register.html')

错误和代码示例似乎不匹配<代码>'user'是一个文本,但需要一个标识符,因此出现错误。带引号的标识符使用双引号。另外,
user
在Postgresql中是保留的,所以您需要使用带引号的标识符。非常感谢。我把用户改成了会员,去掉了所有的引语,效果很好。