SqlAlchemy - PostgreSQL - 会话连接错误的信息



我编写了以下代码来连接到数据库并填充架构:

db_url = 'postgresql+psycopg2:///bidder:<pass>@localhost:5432/basketball'
Engine = create_engine(db_url, echo=False)
SessionMaker = ORM.sessionmaker(bind=Engine, autoflush=False)
Session = ORM.scoped_session(SessionMaker)
Base.metadata.create_all(Engine)

然而,最后一句话提出了:

(psycopg2.OperationalError) FATAL:  role "fran" does not exist

("Fran"是我的Unix用户名)

Sqlalchemy 没有使用我在db_url中指定的用户名和密码连接到数据库。

List of databases
    Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
------------+----------+----------+-------------+-------------+-----------------------
 basketball | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
            |          |          |             |             | postgres=CTc/postgres+
            |          |          |             |             | bidder=CTc/postgres
 postgres   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
            |          |          |             |             | postgres=CTc/postgres
 template1  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
            |          |          |             |             | postgres=CTc/postgres

用户表:

 rolname  
----------
 postgres
 bidder
(2 rows)

尝试从db_url中删除其中一个/

db_url = 'postgresql+psycopg2://bidder:<pass>@localhost:5432/basketball'

最新更新