python - 使用Python和SQLite创建表,没有这样的表

标签 python sql python-3.x sqlite

我正在使用Python通过SQLite3创建一个表,我被告知该表已在解释器中创建,但是当在cmd中查看该表时,没有这样的表。这是我的代码:

import sqlite3 as db

conn = db.connect('test.db')
cursor = conn.cursor()
cursor.execute("create table films(title text, year text, director text)")
print("tables added")

在解释器中我得到:

>>> ================================ RESTART ================================
>>> 
tables added

但是当我在 cmd 中通过 SQLite 查看数据库时,我被告知:

Error: no such table: films

最佳答案

确保在同一目录中运行脚本和解释器。否则它们引用两个不同的数据库文件。

关于python - 使用Python和SQLite创建表,没有这样的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21967787/

相关文章:

python - 如何在此 pandas 数据框上正确使用数据透视表?

python - 在每个数据点处带有对齐注释的散点图

sql - 如何在空白值上使用 PIVOT 子句

php - 从结果集中选择最新记录(mysql、php)

python - Bing Congitive Web 搜索 API 与 Python 3

Python:并行运行多个网络请求

python - 在MySQL-Python中使用INSERT INTO语句的语法错误

python - 将多个时间值分组为开始时间和结束时间

mysql - 提取从今天起 9 天后发生的数据(登录日期)

python-3.x - 断言失败: [Condition x == y did not hold element-wise:]