原文链接:http://www.juzicode.com/archives/3940
错误提示:
sqlite3建表时提示:sqlite3.OperationalError: table table_juzicode already exists
#juzicode.com/vx:桔子code
import sqlite3
db_name = 'test.db'
table_name = 'table_juzicode'
conn = sqlite3.connect(db_name)
cursor = conn.cursor()
sql = '''CREATE TABLE '''+table_name +''' (
_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
price FLOAT,
weight FLOAT
)'''
cursor.execute(sql)
==========运行结果:
---------------------------------------------------------------------------
OperationalError
Traceback (most recent call last) <ipython-input-7-0d0e9d4b9ba1> in <module>
11 weight FLOAT
12 )'''
---> 13 cursor.execute(sql)
<

本文讲述了在使用Python的sqlite3模块创建表时遇到'OperationalError: table already exists'的解决方法,通过先查询表是否存在再决定是否新建,确保表的正确创建。
最低0.47元/天 解锁文章
365

被折叠的 条评论
为什么被折叠?



