为什么我突然收到“OperationalError: no such table"? [英] Why am I suddenly getting "OperationalError: no such table"?

查看:46
本文介绍了为什么我突然收到“OperationalError: no such table"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用我的数据库做各种事情.我已经成功地连接并拉出数据和拉出数据,没有问题.我一直在调试其他问题,然后突然我无法再从我的数据库表中获取任何信息 - 我收到OperationalError:没有这样的表:文章".

I am trying to do various things with my database. I've connected and pulled data out and out data in, successfully, no problems. I've been debugging other issues, and then suddenly I can no longer get anything from my database table - I'm getting "OperationalError: no such table: article".

我真的被难住了 - 这工作得很好,我查询数据库没有问题,插入数据等等.然后突然我收到这个错误.我在错误开始出现之前所做的更改似乎完全无关 - 我取消了它们但仍然收到此错误.这是我收到错误的脚本的开头:

I'm really stumped here - this was working just fine, I was querying the db with no problems and inserting data, etc etc. Then suddenly I'm getting this error. The changes I made immediately before the error started appearing would seem to be totally unrelated - I undid them and still get this error. Here's the start of my script where I'm getting the error:

import sqlite3

database='mydatabase'
db=sqlite3.connect(database)
c=db.cursor()

sql_command='SELECT id FROM article'
idlist=c.execute(sql_command)

我可以在 SQLite Administrator 中打开该数据库并验证该表是否存在.加上它以前工作过.我还尝试通过以下方式验证该表是否在其中:

I can open that database in SQLite Administrator and verify the table is there. Plus it was working before. I've also tried to verify that the table is in there by:

>>c.execute('select name from sqlite_master where type="table"').fetchall()
[]

所以有些东西真的很古怪.

so something is really wacky.

我还尝试关闭并重新打开数据库连接和游标.并关闭 Python 会话.没有骰子.帮助!

I've also tried closing and reopening the db connection and cursor. And closing the Python session. No dice. Help!

推荐答案

您是否将代码移至其他地方?

did you moved your code to another place?

因为sqlite将数据库存储到一个文件中,所以调用connect时,如果存在名为'mydatabase'的文件,则加载,否则加载.将自动创建一个新的数据库文件.

because sqlite store the database into a file, when you call connect, if a file with the name 'mydatabase' exist, it will be loaded, otherwise. a new fresh database file will be created automatically.

搜索名为 'mydatabase' 的旧文件并将其放入您的代码中.

search for your old file with name 'mydatabase' and put it within your code.

这篇关于为什么我突然收到“OperationalError: no such table"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆