python-3.x - psycopg2.ProgrammingError:无效的dsn:无效的连接选项“dBname”
问题描述
我试图在 PostgreSQL 中创建一个表,当我输入以下代码时,我收到错误:
psycopg2.ProgrammingError:无效的dsn:无效的连接选项“dBname”
代码:
def create():
conn=psycopg2.connect("dBname='database1' user='postgres' password='postgres' host='localhost'
port='5432'")
cur=conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS store(item TEXT,quantity INTEGER,price REAL)")
conn.commit()
conn.close()
终端: psycopg2.ProgrammingError:无效的dsn:无效的连接选项“dBname”
解决方案
conn=psycopg2.connect("dBname=database1 user=postgres password=postgres host=localhost")