2

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.

I'm using PostgreSQL 9.1.

X-Istence
  • 16,324
  • 6
  • 57
  • 74
  • 1
    I fixed your tags for you. No idea about Pyramid, so can't help there. BTW, why use PostgreSQL 9.1 on a new application? – Craig Ringer Jul 11 '14 at 10:10
  • You can look at the initializedb.py from an example app (called Wiki2, which is used as a tutorial): http://docs.pylonsproject.org/projects/pyramid/en/latest/tutorials/wiki2/definingmodels.html#changing-scripts-initializedb-py – Raj Jul 11 '14 at 12:58

1 Answers1

7

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)

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

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.

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 .

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

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

pdepmcp
  • 136
  • 1
  • 4