Reputation: 25928
I'm attempting to create a PostgreSQL database using PeeWee
. Upon connecting I get the following error:
File "peewee_test.py", line 44, in
psql_db.connect()
File "c:\python27\lib\site-packages\peewee.py", line 3602, in connect
self.initialize_connection(self._local.conn)
File "c:\python27\lib\site-packages\peewee.py", line 3514, in exit
reraise(new_type, new_type(*exc_args), traceback)
File "c:\python27\lib\site-packages\peewee.py", line 3600, in connect
**self.connect_kwargs)
File "c:\python27\lib\site-packages\playhouse\postgres_ext.py", line 385, in _connect
conn = super(PostgresqlExtDatabase, self)._connect(database, **kwargs)
File "c:\python27\lib\site-packages\peewee.py", line 3990, in _connect
conn = psycopg2.connect(database=database, **kwargs)
File "c:\python27\lib\site-packages\psycopg2__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
peewee.OperationalError: FATAL: database "test" does not exist
Any idea what I am doing wrong?
from peewee import *
from playhouse.postgres_ext import PostgresqlExtDatabase
psql_db = PostgresqlExtDatabase(
'test', # Required by Peewee.
user='xxxxx', # Will be passed directly to psycopg2.
password='xxxxx', # Ditto.
host='', # Ditto.
port='5432'
)
psql_db.connect() # error occurs here
psql_db.create_tables([Person, Pet])
Upvotes: 1
Views: 2377
Reputation: 189
Peewee wont create the database for you, you need to first connect to the database with psql shell for example and admin user access psql --host HOST --port 5432 --username YOUR_USER -W -d postgres
and run CREATE DATABASE test;
Postgres has also a helper createdb
executable:
createdb my_db
Upvotes: 1