I wrote the following code to connect to the database and fill the schema:
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)
That last statement, however, raises:
(psycopg2.OperationalError) FATAL: role "fran" does not exist
("fran" is my unix username)
Sqlalchemy is not connecting to the database with the username and password I'm specifying in 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
Users table:
rolname
----------
postgres
bidder
(2 rows)
尝试从db_url中删除/
之一。
db_url = 'postgresql+psycopg2://bidder:<pass>@localhost:5432/basketball'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.