简体   繁体   English

为什么我突然收到“OperationalError:没有这样的表”?

[英]Why am I suddenly getting "OperationalError: no such table"?

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".我一直在调试其他问题,然后突然间我无法再从我的数据库表中获取任何内容 - 我收到“OperationalError:没有这样的表:文章”。

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)

I can open that database in SQLite Administrator and verify the table is there.我可以在 SQLite Administrator 中打开该数据库并验证该表是否存在。 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.所以有些事情真的很古怪。

I've also tried closing and reopening the db connection and cursor.我还尝试关闭并重新打开数据库连接和游标。 And closing the Python session.并关闭 Python 会话。 No dice.没有骰子。 Help!帮助!

Did you move your code to another place?你把你的代码移到另一个地方了吗?

SQLite stores the database into a file, and when you call connect, if a file with the name 'mydatabase' exists, it will be loaded. SQLite 将数据库存储到一个文件中,当您调用连接时,如果存在名为'mydatabase'的文件,它将被加载。 Otherwise, a new fresh database file will be created automatically.否则,将自动创建一个新的新数据库文件。

Search for your old file with the name 'mydatabase' and put it within your code.搜索名称为'mydatabase'的旧文件并将其放入您的代码中。

I had exactly the same problem with sqlite3 and flask accessing a database.我在访问数据库时遇到了与 sqlite3 和 flask 完全相同的问题。 I changed the path to the database in my code to its full path and this solved the problem of data disappearing and tables not being found after restarting my flask application.我将代码中的数据库路径更改为其完整路径,这解决了重启 Flask 应用程序后数据消失和找不到表的问题。 I can recommend SQLite Manager firefox plugin, which helps with viewing records in your database tables.我可以推荐 SQLite Manager firefox 插件,它有助于查看数据库表中的记录。 Follow this link to see a similar problem solved using full path references to your database Django beginner problem: manage.py dbsync点击此链接可查看使用数据库完整路径引用解决的类似问题Django 初学者问题:manage.py dbsync

Python does not do path expansion.so you might want to use Environment variables to store paths to your database. Python 不进行路径扩展。因此您可能希望使用环境变量来存储数据库的路径。 Link to WingWare's Environment Variable expansion链接到 WingWare 的环境变量扩展

I had the the problem.我遇到了问题。 In my case, before trying to access the database I have this line:就我而言,在尝试访问数据库之前,我有这一行:

 os.chdir("other/dir")
 conn = sqlite3.connect("database.db")

So sqlite3 create an empty database in that dir instead.所以 sqlite3 在该目录中创建一个空数据库。

I had the same problem, in my case i was creating trying to create Tables before tables before creating tables, here is an example我遇到了同样的问题,在我的例子中,我正在尝试在创建表之前先创建表,这是一个示例

Base.metadata.create_all(bind=engine)  # Wrong placement

class Currency(Base):
    __tablename__ = "currency"
    date = Column(Date, primary_key = True)
    rates = Column(String)

I fixed it with replacing the position of Base Creator我通过替换 Base Creator 的位置来修复它

class Currency(Base):
    __tablename__ = "currency"
    date = Column(Date, primary_key = True)
    rates = Column(String)

Base.metadata.create_all(bind=engine)  # Right placement

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我会收到 peewee.OperationalError - Why am i getting peewee.OperationalError Django-为什么在使用外壳程序时会出现OperationalError(仅)? - Django - Why am I getting an OperationalError (only) when I am using the shell? Django,Boto,S3:为什么我突然没有得到回应? - Django, Boto, S3: Why am I not getting a response suddenly? 为什么在Python进行SQL调用期间我在'VARCHAR'附近出现了操作错误? - Why am I getting the operationalerror near 'VARCHAR' during SQL call in Python? 为什么我在尝试从本地谷歌云 function 连接到谷歌云 MySQL db 时收到 sqlalchemy.exc.OperationalError? - Why am I getting sqlalchemy.exc.OperationalError when trying to connect to Google Cloud MySQL db from a local google cloud function? 以下错误是我从下面的代码片段中得到的。 sqlite3.OperationalError:表记录有 7 列,但提供了 6 个值 - the following error is what I am getting from the code snippet below. sqlite3.OperationalError: table record has 7 columns but 6 values were supplied 为什么我突然出现“python.dll is not installed”错误? - Why am I suddenly "python.dll is not installed" error? 我偶尔收到此错误:sqlite3.OperationalError:无法打开数据库文件 - I am sporadically getting this error : sqlite3.OperationalError: unable to open database file 为什么我收到此错误:_mysql_exceptions.OperationalError:(1241,'Operand应该包含1列') - Why am I receiving this error: _mysql_exceptions.OperationalError: (1241, 'Operand should contain 1 column(s)') 为什么我得到这个ImportError? - Why am I getting this ImportError?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM