flask 学习错误总结 (sqlite3.OperationalError) no such table / no such column

在学习Flask时遇到sqlite3.OperationalError错误,原因是数据库表格缺失。解决方案包括检查数据库配置,确保运行迁移命令更新数据库结构。在项目开始时,使用`python db create`、`python db migrate`、`python db upgrade`。当数据库更改后,需运行`python db migrate`和`python db upgrade`进行更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在学习flask狗书的时候在第七章的时候将hello.py分解成为程序结构的时候  出现这个

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: users [SQL: 'SELECT users.id AS users_id, users.username AS users_username, users.role_id AS users_role_id \nFROM users \nWHERE users.username = ?\n LIMIT ? OFFSET ?']


在谷歌了很久以后发现了 作者的回答 you probably missed the fact that after the restructure in chapter 7 the name of the database has changed. Post chapter 7 the application has multiple configurations, and each configuration uses a different database. So you are probably using an empty database that has no tables. If you run manage.py db upgrade you s

INFO: Started server process [4020] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit) INFO: 127.0.0.1:55021 - "GET / HTTP/1.1" 200 OK INFO: 127.0.0.1:55021 - "GET /styles.css HTTP/1.1" 200 OK INFO: 127.0.0.1:55022 - "GET /script.js HTTP/1.1" 200 OK ERROR:__main__:随访检查任务失败: no such column: f.reminder_sent Traceback (most recent call last): File "D:\PythonProjects\prediction\main.py", line 453, in check_followups followups = conn.execute(&#39;&#39;&#39; ~~~~~~~~~~~~^^^^ SELECT f.id, p.name, p.contact, p.doctor_username ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... WHERE f.scheduled_date = ? AND f.status = &#39;pending&#39; AND f.reminder_sent = 0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ &#39;&#39;&#39;, (tomorrow,)).fetchall() ^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such column: f.reminder_sent INFO: 127.0.0.1:55025 - "POST /api/login HTTP/1.1" 405 Method Not Allowed INFO: 127.0.0.1:55034 - "POST /api/register HTTP/1.1" 405 Method Not Allowed INFO: 127.0.0.1:55034 - "POST /api/register HTTP/1.1" 405 Method Not Allowed INFO: 127.0.0.1:55034 - "POST /api/login HTTP/1.1" 405 Method Not Allowed INFO: Started server process [4020] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit) INFO: 127.0.0.1:55021 - "GET / HTTP/1.1" 200 OK INFO: 127.0.0.1:55021 - "GET /styles.css HTTP/1.1" 200 OK INFO: 127.0.0.1:55022 - "GET /script.js HTTP/1.1" 200 OK ERROR:__main__:随访检查任务失败: no such column: f.reminder_sent Traceback (most recent call last): File "D:\PythonProjects\prediction\main.py", line 453, in check_followups followups = conn.execute(&#39;&#39;&#39; ~~~~~~~~~~~~^^^^ SELECT f.id, p.name, p.contact, p.doctor_username ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... WHERE f.scheduled_date = ? AND f.status = &#39;pending&#39; AND f.reminder_sent = 0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ &#39;&#39;&#39;, (tomorrow,)).fetchall() ^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such column: f.reminder_sent 给你我的代码你仔细思考,然后解决这些问题,记住这只是一个本科毕设,不需要你做多么大多么难的界面,主要是实现已有的这些功能然后完善,能够出现界面即可,不要扩充,有错误错误,有问题解决问题,赶紧加油,很快就到截止日期了,真的求求你
最新发布
05-12
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值