SQLite 报告我的表不存在,即使我可以手动找到它

发布于 2025-01-10 12:33:32 字数 1006 浏览 0 评论 0原文

我正在构建一个简单的应用程序,主要基于 Python Flask 教程。当尝试在 SQLite 数据库中创建数据时,我始终收到一条错误,指出我的表不存在:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: user
[SQL: INSERT INTO user (username, password, salt, email) VALUES (?, ?, ?, ?)]
[parameters: (redacted)
(Background on this error at: https://sqlalche.me/e/14/e3q8)

为了调试此错误,我在引发异常的行之前添加了以下行:

print(db.metadata.tables)

令人费解的是,这元数据显示我的 user 表确实存在:

FacadeDict({'user': Table('user', MetaData(), Column('id', Integer(), table=<user>, primary_key=True, nullable=False), Column('username', String(length=80), table=<user>, nullable=False), Column('password', String(length=100), table=<user>, nullable=False), Column('salt', String(length=100), table=<user>, nullable=False), Column('email', String(length=120), table=<user>), schema=None))

我一直在兜圈子,试图找出为什么会发生这种情况,但相互冲突的调试信息让我失去了想法。是否有一些明显的事情我可能会忽略,或者我是否误解了该错误?

I am building a simple application, mostly based on the Python Flask tutorial. When trying to create data in my SQLite database, I consistently receive an error saying that my table doesn't exist:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: user
[SQL: INSERT INTO user (username, password, salt, email) VALUES (?, ?, ?, ?)]
[parameters: (redacted)
(Background on this error at: https://sqlalche.me/e/14/e3q8)

In order to debug this error, I have added the following line just before the line that throws the exception:

print(db.metadata.tables)

And inexplicably, this metadata shows that my user table does exist:

FacadeDict({'user': Table('user', MetaData(), Column('id', Integer(), table=<user>, primary_key=True, nullable=False), Column('username', String(length=80), table=<user>, nullable=False), Column('password', String(length=100), table=<user>, nullable=False), Column('salt', String(length=100), table=<user>, nullable=False), Column('email', String(length=120), table=<user>), schema=None))

I have been going in circles trying to figure out why this might be happening, but the conflicting debug information is making me run out of ideas. Is there something obvious that I might be overlooking, or am I misunderstanding the error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文