0

I am using the following code to create postgresql database using sqlalchemy:

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

But it gives me the following error even though I manually created the database in 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

Why is this happening?

1 Answer 1

5

You need to create the database beforehand, create_all just creates the tables. To create database: sudo -u postgres createdb testData.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.