PostgreSQL schema support

438 views
Skip to first unread message

Christoph Haas

unread,
Jan 5, 2007, 2:26:15 PM1/5/07
to django...@googlegroups.com
Dear list...

I'm currently starting a larger project and want to use Django for it.
First order of business was creating the necessary database schema with
pgadmin3 (a PostgreSQL GUI). Next thing after setting my settings.py right
was to run "django-admin inspectdb" to get my already existing database
schema into a models.py. Unfortunately the models.py was mostly empty. I
figured out it's due to my use of PostgreSQL schemas. Django just didn't
find my tables.

/*
Where other DBMS like MySQL just have databases and tables you can use an
additional layer to seperate different applications or parts of your
application into schemas. Where in MySQL you have database->table you have
database->schema->table in PostgreSQL. You query them through e.g.

SELECT * from schemaname.tablename;

You may think of those schemas just as different namespaces. The default
namespace is 'public' and automatically prepended through a search path
variable.
*/

The problem has been raised in
- http://code.djangoproject.com/ticket/1051
- http://code.djangoproject.com/ticket/1208
already.

I'm running Django 0.95 on Debian.

Did anyone else find a workaround? Is it meanwhile possible to use at least
a models.py without using "inspectdb"? My experiments
with 'schemaname.tablename' just lead me
to "public"."schemaname.tablename" which is obviously not what I want.

I'd like to hear comments. Or is PostgreSQL an uncommon DBMS to use with
Django? (btw, is there a reason to prefer psycopg over psycopg2?) I can of
course restrain myself to the "public" schema but my application would
benefit from different schemas.

Kindly
Christoph

Russell Keith-Magee

unread,
Jan 5, 2007, 7:46:20 PM1/5/07
to django...@googlegroups.com
On 1/6/07, Christoph Haas <em...@christoph-haas.de> wrote:
>
> The problem has been raised in
> - http://code.djangoproject.com/ticket/1051

> Did anyone else find a workaround? Is it meanwhile possible to use at least


> a models.py without using "inspectdb"? My experiments
> with 'schemaname.tablename' just lead me
> to "public"."schemaname.tablename" which is obviously not what I want.
>
> I'd like to hear comments. Or is PostgreSQL an uncommon DBMS to use with
> Django? (btw, is there a reason to prefer psycopg over psycopg2?) I can of
> course restrain myself to the "public" schema but my application would
> benefit from different schemas.

Postgres is the database that is used by most of the core developers,
AFAIK (it's certainly my DB of choice, and Jacob has blogged Postgres
as his preference in the past). The only reason to prefer psycopg over
psycopg2 is historical - the API for psycopg2 wasn't finalized until
quite recently, so we didn't recommend using it. However, the psycopg
backend has a few problems with unicode, so I suspect the official
line may soon switch to 'use v2' (probably before Django goes v1.0).

Regarding schema - I can't think of any fundamental objection to
including them, other than whatever method is used must degrade
gracefully to the other DB backends. The reason that ticket #1051
hasn't received any attention is because it simply isn't a priority
for the core developers. Personally, I've never had a Django-related
application where namespacing became anything close to a problem
requiring a solution.

However, if someone were to do a good triage job (see the docs for
what this means - and for the record, this would constitute a 'big
change'), and the required changes degraded gracefully to the other
backends, and there was documentation, and there were tests exercising
the functinoality, I don't see any reason that support for Postgres
schemas couldn't be included.

Yours,
Russ Magee %-)

Kenneth Gonsalves

unread,
Jan 5, 2007, 10:03:38 PM1/5/07
to django...@googlegroups.com

On 06-Jan-07, at 12:56 AM, Christoph Haas wrote:

> I'd like to hear comments. Or is PostgreSQL an uncommon DBMS to use
> with Django? (btw, is there a reason to prefer psycopg over
> psycopg2?) I can of course restrain myself to the "public" schema
> but my application would benefit from different schemas.

postgres is the rdbms of choice for django. psycopg1 and 2 are
incompatible - and there is so much legacy code in psycopg1 that many
users are unwilling to switch. I agree with you with regard to
schemas - for example a multicompany financial accounting application
could use schemas to create the tables for each company.

--

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/


Reply all
Reply to author
Forward
0 new messages