我使用以下代码使用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
为什么会这样
您需要事先创建数据库,
create_all
只需创建表。要创建数据库:sudo -u postgres createdb testData
相关问题 更多 >
编程相关推荐