找不到包含SQLalchemy数据库的PostgreSQL

2024-10-01 04:45:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用以下代码使用sqlalchemy创建postgresql数据库:

engine=create_engine('postgresql+psycopg2://postgres@localhost/testData')
Base.metadata.create_all(engine)

但是,即使我在psql中手动创建了数据库,它也会给我以下错误:

  File "/home/ubuntu/venve/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 376, in connect
return self.dbapi.connect(*cargs, **cparams)
  File "/home/ubuntu/venve/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
  conn = _connect(dsn, connection_factory=connection_factory, async=async)
sqlalchemy.exc.OperationalError: (OperationalError) FATAL:  database "testData" does not exist

为什么会这样


Tags: 数据库homesqlalchemypostgresqlubuntuliblocalconnect