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?

Cœur
39k25 gold badges207 silver badges282 bronze badges
asked Apr 16, 2014 at 20:53

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.

answered Apr 16, 2014 at 21:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.