PeeWee PostgreSQL数据库创建:不存在

时间:2016-11-06 03:10:29

标签: python postgresql peewee

我尝试使用PeeWee创建PostgreSQL数据库。连接后,我收到以下错误:

  

文件" peewee_test.py",第44行,在      psql_db.connect()
   文件" c:\ python27 \ lib \ site-packages \ peewee.py",第3602行,在连接中      self.initialize_connection(self._local.conn)
   文件" c:\ python27 \ lib \ site-packages \ peewee.py",第3514行,退出
     reraise(new_type,new_type(* exc_args),traceback)
   文件" c:\ python27 \ lib \ site-packages \ peewee.py",第3600行,在连接中      ** self.connect_kwargs)
   文件" c:\ python27 \ lib \ site-packages \ playhouse \ postgres_ext.py",第385行,在_connect
中      conn = super(PostgresqlExtDatabase,self)._ connect(数据库,** kwargs)
   文件" c:\ python27 \ lib \ site-packages \ peewee.py",第3990行,在_connect
中      conn = psycopg2.connect(database = database,** kwargs)
   文件" c:\ python27 \ lib \ site-packages \ psycopg2__init __。py",第164行,在连接中
     conn = _connect(dsn,connection_factory = connection_factory,async = async)
  peewee.OperationalError:致命:数据库"测试"不存在

知道我做错了吗?

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])

1 个答案:

答案 0 :(得分:1)

Peewee不会为您创建数据库,例如,您需要先使用psql shell连接到数据库,并且管理员用户访问权限psql --host HOST --port 5432 --username YOUR_USER -W -d postgres并运行CREATE DATABASE test;

Postgres还有一个辅助程序createdb可执行文件:

createdb my_db
相关问题