年中初界
2021-08-26 22:41
采纳率: 100%
浏览 16
已结题

flask中使用FLASK-SQLAIchemy管理数据库

flask中的数据库操作(创建用户及角色)报错

>>> from hello import db
>>> db.drop_all()
>>> from hello import Role, User
>>> admin_role = Role(name='Admin')
>>> mod_role = Role(name='Moderator')
>>> user_role = Role(name='User')
>>> user_john = User(username='john', role=admin_role)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "<string>", line 4, in __init__
  File "e:\pythonproject\flask-future\venv\lib\site-packages\sqlalchemy\orm\state.py", line 480, in _initialize_instance
    manager.dispatch.init_failure(self, args, kwargs)
  File "e:\pythonproject\flask-future\venv\lib\site-packages\sqlalchemy\util\langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "e:\pythonproject\flask-future\venv\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
    raise exception
  File "e:\pythonproject\flask-future\venv\lib\site-packages\sqlalchemy\orm\state.py", line 477, in _initialize_instance
    return manager.original_init(*mixed[1:], **kwargs)
  File "e:\pythonproject\flask-future\venv\lib\site-packages\sqlalchemy\orm\decl_base.py", line 1142, in _declarative_constructor
    raise TypeError(
TypeError: 'username' is an invalid keyword argument for User

  • 收藏

1条回答 默认 最新

  • Leleprogrammer 2021-08-31 15:43
    已采纳

    第1行就报错,那么就说明你的hello文件里有错误,建议根据报错信息检查一下hello文件里的代码

    1 打赏 评论

相关推荐 更多相似问题