[英]Python Error No such table using sqlite3
今天第一次嘗試使用Python,並且幾乎立即陷入了跟隨和示例的困境。 在Windows上使用Pyhon 3.6。 有人可以幫忙嗎?
RESTART: C:/Users/tom_/AppData/Local/Programs/Python/Python36-32/Projects/Database/dbexample.py
Traceback (most recent call last):
File "C:/Users/tom_/AppData/Local/Programs/Python/Python36-32/Projects/Database/dbexample.py", line 13, in <module>
enter_data()
File "C:/Users/tom_/AppData/Local/Programs/Python/Python36-32/Projects/Database/dbexample.py", line 11, in enter_data
c.execute("INSERT INTO Example VALUES('Python', 2.7, 'Beginner')")
sqlite3.OperationalError: no such table: Example
碼:
import sqlite3
conn = sqlite3.connect('tutorial.db')
c = conn.cursor()
def create_table():
c.execute("CREATE TABLE Example(Language VARCHAR, Version REAL, Skill TEXT)")
def enter_data():
c.execute("INSERT INTO Example VALUES('Python', 2.7, 'Beginner')")
enter_data()
conn.close()
您需要先調用create_table()
,然后才能將enter_data()
用於新數據庫。 一旦創建它,您將得到一個sqlite3.OperationalError: table Example already exists
如果再次調用它sqlite3.OperationalError: table Example already exists
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.