【发布时间】:2021-12-20 01:28:24
【问题描述】:
SQLite 表示“ORGANIZATION”表已经存在。
这是我的代码:
import sqlite3
con = sqlite3.connect('example4.db')
cur = con.cursor()
# Create table
cur.execute('''CREATE TABLE ORGANIZATION
(ID int, NAME text, SURNAME text, NICKNAME text, ADDRESS chair(250), PHONE
real, MAIL text, WEB text, INFO chair(250) )''')
# Insert a row of data
cur.execute("INSERT INTO ORGANIZATION VALUES (1, 'John', 'Stockton', 'JS', 'Nip and Tack 15',
00000000000, 'info@info.xx',' https://www.info.xx', '-' )")
# Save (commit) the changes
con.commit()
con.close()
con = sqlite3.connect('example4.db')
cur = con.cursor()
for row in cur.execute('SELECT * FROM ORGANIZATION ORDER BY ID'):
print(row)
我的预期结果是打印带有表格数据的行:
1, 'John', 'Stockton', 'JS', 'Nip and Tack 15', 00000000000, 'info@info.xx',' https://www.info.xx', '-'
【问题讨论】:
-
您可能已经多次运行该程序,因此之前执行的表仍然存在于
example4.db。 -
使用:CREATE TABLE IF NOT EXISTS ORGANIZATION ...