sqlalchemy.exc.ProgrammingError: (_mysql_exceptions.ProgrammingError) (1146, "Table 'xxx.authority' doesn't exist")

  • 操作

    • 我是在写项目中把全部的表都删了, 然后进行新建
    if __name__ == '__main__':
        db.create_all()
    
    
  • 报错内容

    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
         省略...............
    File "XXXappadminforms.py", line 10, in <module>
        authority_list = [(v.id, v.name) for v in Authority.query.all()]
         省略...............
    sqlalchemy.exc.ProgrammingError: (_mysql_exceptions.ProgrammingError) (1146, "Table 'xxx.authority' doesn't exist") [SQL: 'SELECT authority.id AS authority_id, authority.name AS authority_name, authority.url AS authority_url, authority.add_time AS authority_add_time 
    FROM authority'] (Background on this error at: http://sqlalche.me/e/f405)
    
    Process finished with exit code 1
    
  • 分析

    • 我们可以从上述内容中知道他是,表不存在,然而他却在forms.py先进行查询, emmmmmmm
  • 解决方法

    • 在forms.py中先将查询部分注释, 执行完db.creat_all()后,再去掉注释
    authority_list = []
    #authority_list = [(v.id, v.name) for v in Authority.query.all()]
    
原文地址:https://www.cnblogs.com/twfb/p/8931845.html