sqlalchemy.exc.NoSuchModuleError:无法加载插件:sqlalchemy.dialects:postgres [英] sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
本文介绍了sqlalchemy.exc.NoSuchModuleError:无法加载插件:sqlalchemy.dialects:postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用SQLAlchemy连接到Postgres数据库.我已经安装了psycopg2.但是,我收到错误 sqlalchemy.exc.NoSuchModuleError:无法加载插件:sqlalchemy.dialects:postgres
.如何配置SQLAlchemy以连接到PostgreSQL?
I'm trying to connect to a Postgres database with SQLAlchemy. I've installed psycopg2. However, I get the error sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
. How do I configure SQLAlchemy to connect to PostgreSQL?
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "postgres://username@localhost:5432/template1"
db = SQLAlchemy(app)
推荐答案
URI应该以 postgresql://
开头,而不是 postgres://
.SQLAlchemy曾经接受两者,但已删除了对 postgres
名称的支持.
The URI should start with postgresql://
instead of postgres://
. SQLAlchemy used to accept both, but has removed support for the postgres
name.
这篇关于sqlalchemy.exc.NoSuchModuleError:无法加载插件:sqlalchemy.dialects:postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文