AttributeError:使用flask-sqlalchemy连接到sqlite数据库时无法设置属性

安装supervisor-cesi的时候,使用sqlite数据库 登录报错

sa_url.database = os.path.join(app.root_path, sa_url.database)

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "c:\coding-projects\task-master-tdd\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 1060, in __repr__
    self.engine.url if self.app or current_app else None
  File "c:\coding-projects\task-master-tdd\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 943, in engine
    return self.get_engine()
  File "c:\coding-projects\task-master-tdd\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 962, in get_engine
    return connector.get_engine()
  File "c:\coding-projects\task-master-tdd\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 555, in get_engine
    options = self.get_options(sa_url, echo)
  File "c:\coding-projects\task-master-tdd\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 570, in get_options
    self._sa.apply_driver_hacks(self._app, sa_url, options)
  File "c:\coding-projects\task-master-tdd\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 914, in apply_driver_hacks
    sa_url.database = os.path.join(app.root_path, sa_url.database)
AttributeError: can't set attribute

解决方法:

SQLAlchemy自动作为Flask-SQLAlchemy的依赖项安装,其最新版本(1.4.0)引入了以下突破性的更改:

URL对象现在是一个名为tuple的不可变对象。要修改URL对象,请使用URL.set()方法生成新的URL对象。

我只需安装以前版本的SQLAlchemy(1.3.23)就可以解决这个问题。


pip install  --upgrade sqlalchemy==1.3.23


ok

版权声明:本文为作者原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原创文章,作者:老C,如若转载,请注明出处:https://www.code404.icu/661.html

发表评论

登录后才能评论

评论列表(1条)