金字塔PostgreSQL连接 [英] Pyramid postgresql connection

查看:115
本文介绍了金字塔PostgreSQL连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对金字塔完全陌生。我正在尝试开发一个同时使用金字塔和PostgreSQL的应用程序,但是我对如何在sripts目录中配置initializedb.py文件(尤其是初始化数据库)感到困惑。

I am totally new to pyramid.I am trying to develop an application that will use both pyramid angd postgresql but i am totally confused about how to configure the initializedb.py file in the sripts directory especially initializing the database.

我正在使用PostgreSQL 9.1。

I'm using PostgreSQL 9.1.

推荐答案

如果我理解您的问题,您只需要找出在何处配置与数据库的连接。我假设您创建了一个基于sqlAlchemy的项目。
在金字塔应用程序的根目录中,您可以找到ini文件。默认情况下,您应该具有development.ini和production.ini文件。前者用于开发,后者用于生产环境,因此它们在某些配置上可以(并且应该)有所不同。

If I understand your question, you just need to find out where to configure the connection to DB. I assume you created a sqlAlchemy based project. In the root of the pyramid app you can find the ini files. By default you should have development.ini and production.ini files. The former is used for development and the latter for production environment, so they can (and should) differ for some configurations.

在两个文件中,您都应该找到这样的行:

In both files you should find a line like this:

sqlalchemy.url = sqlite:///%(here)s/dbname.sqlite

您只需要使用以下内容更改该行:

You just need to change that line with something like this:

sqlalchemy.url = postgresql://DBUser:DBPassword@DBHostNameOrIP:5432/DBName

(根据需要提供必需的参数)

(sustitute parameters as needed)

直接使用initializedb.py,但应使用initialize_YourProject_db脚本(在bin文件夹中,该目录从金字塔根),像这样:

Whe you use initializedb.py directly, but you should use the initialize_YourProject_db script (in the bin folder, one dir back from the pyramid root), like this:

initialize_YourProject_db development.ini

其中 YourProject是您在创建项目时定义的项目名称,而development.ini是您要使用的ini文件。

where "YourProject" is the name of your project as defined when you created it and development.ini is the ini file you wish to use.

如果尚未完成,y您可能需要在 setup.py中的所需模块中添加 db-psycopg2,然后执行

If have not done it yet, you may need to add 'db-psycopg2' to your required modules in setup.py and execute

pip install -e .

(最后一个点不是错字)。
请记住,psycopg2(postgresql的驱动程序)具有依赖性(在ubuntu 14_04上,您需要一个 apt-get install libpq-dev python-dev,在其他发行版/ SO中可能有所不同)。

again (the final dot is not a typo). Please remember that psycopg2 (the driver for postgresql) has dependencies (on ubuntu 14_04 you need a 'apt-get install libpq-dev python-dev', it may differ in other distros/SOs).

如果一切正常,脚本将根据您的模型创建所有引用的表,并插入在initializedb.py中定义并添加到DBSession的所有项目

If enaything works fine, the script will create all tables referenced, according to your models, and insert all items defined in initializedb.py and added to the DBSession

这篇关于金字塔PostgreSQL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆