SQLite 报告我的表不存在,即使我可以手动找到它
我正在构建一个简单的应用程序,主要基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论