gpt4 book ai didi

python - Flask 和 Heroku sqlalchemy.exc.NoSuchModuleError : Can't load plugin: sqlalchemy. 方言:postgres

转载 作者:行者123 更新时间:2023-12-04 10:59:18 38 4
gpt4 key购买 nike

当我跑

heroku run python
>>> from app.main import app
>>> app.config['SQLALCHEMY_DATABASE_URI']
'postgres://<url string>' # the database url is passed correctly
>>> from app.main import db
>>> db.create_all()
它给出了这个错误:
  Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 1039, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 1031, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 962, in get_engine
return connector.get_engine()
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 556, in get_engine
self._engine = rv = self._sa.create_engine(sa_url, options)
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 972, in create_engine
return sqlalchemy.create_engine(sa_url, **engine_opts)
File "<string>", line 2, in create_engine
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned
return fn(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/create.py", line 520, in create_engine
entrypoint = u._get_entrypoint()
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/url.py", line 653, in _get_entrypoint
cls = registry.load(name)
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 342, in load
"Can't load plugin: %s:%s" % (self.group, name)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
我很困惑,因为我是 Heroku 和 Postgresql 的新手(直到现在一直在使用 SQLite)而且我所遵循的教程都没有解释它是如何连接到 Flask 的,只有如何做到这一点。所以我不明白要解决什么问题。我应该在问题中包含任何其他代码吗?
(大多数其他问题 like this one 是拼写错误或无法解决此问题的错误。)

最佳答案

这是由于 sqlalchemy 库中的更改。这是在改变方言(SQLALCHEMY_DATABASE_URI 中“:”之前的部分)名称postgres 中宣布的弃用。至 postgresql .他们从这个 github commit 发布了这个突破性的变化。与 minor version release ,这是他们这样做的政策。
Heroku 的默认方言是 postgres在他们提供的 DATABASE_URL 中,它被翻译成 SQLALCHEMY_DATABASE_URI。如果更新不会破坏可能依赖它的其他库,Heroku 可以更新他们的 postgres 附加组件。
同时,您可以将 sqlalchemy 库固定回 <1.4.0(1.3.23 是最后一个 1.3.x 版本),它应该可以工作。
或者,您可以更新代码以修改方言。

关于python - Flask 和 Heroku sqlalchemy.exc.NoSuchModuleError : Can't load plugin: sqlalchemy. 方言:postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66690321/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com