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

来源:互联网 发布:arm linux gcc 4.4.3 编辑:程序博客网 时间:2024/06/05 13:28

在学习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.




原创粉丝点击