由于某些未知原因,未创建数据库中的表。怎么解决?
import psycopg2
conn = psycopg2.connect(user='postgres', host='localhost', password='123456')
conn.autocommit = True
cur = conn.cursor()
cur.execute('CREATE DATABASE example;')
cur.execute("""CREATE TABLE HARMKA
(ID INT PRIMARY KEY NOT NULL,
PHARMACY_LICENSE CHAR(100),
STREET CHAR(150),
CITY CHAR(30));""")
cur.execute("INSERT INTO HARMKA VALUES(%s, %s, %s, %s)", (1, '12345', 'street', 'Denwer'))
cur.close()
conn.close()
答案 0 :(得分:3)
您需要连接到example
数据库,然后创建表并操作数据。
conn = psycopg2.connect(database='example', user='postgres', host='localhost', password='123456')