您的位置:首页 > 数据库 > SQL

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

2017-10-21 10:12 633 查看
在学习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 should get the tables added to your database. 确实是因为忘记了红色标记的这一步骤 

然后运行了此步骤过后 程序正常

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: users.confirmed [SQL: 'SELECT users.id AS users_id, users.email AS users_email, users.username AS users_username, users.role_id
AS users_role_id, users.password_hash AS users_password_hash, users.confirmed AS users_confirmed \nFROM users \nWHERE users.email = ?\n LIMIT ? OFFSET ?'] [parameters: ('john@example.com', 1, 0)]

出现此错误是因为在修改了数据库的数据后没有使用 .py db migrate 根据作者的回答可以很清晰的看出每次该怎么做

It goes like this:

When you begin your project, use 
db init
, followed by 
db migrate
, followed by 
db upgrade
.
When you make changes to your database, use 
db migrate
, followed by 
db upgrade
.
When you install your code on a new machine, or need to recreate the database from scratch, use 
db upgrade
.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  flask