inspectdb and non "public" schema in postgresql

1,306 views
Skip to first unread message

Fabio C. Barrionuevo da Luz

unread,
May 19, 2014, 5:38:20 PM5/19/14
to django-d...@googlegroups.com
Hello Django core developers.
Sorry if this is not the correct place to handle this.

I have a legacy database in PostgreSQL, which is still in production.
I want to migrate it to Django. 
I tried to do the reverse engineering of the database to generate models classes

I set my settings like this:

DATABASES = {
    # this read/write into "public" postgresql schema
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'neweposse',
        'USER': 'neweposse_user',
        'PASSWORD': 'neweposse_user',
        'HOST': '127.0.0.1',
        'PORT': '5432',      
    },
    # legacy database
    'eposse': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'eposse',
        'USER': 'eposse_user',
        'PASSWORD': 'eposse_user',
        'HOST': '127.0.0.1',
        'PORT': '5432',    
    }
}


in terminal:

(django1.7a5)sutransdev@sutransdev:~/webdocpy$ python manage.py inspectdb
...
from __future__ import unicode_literals

from django.db import models

(django1.7a5)sutransdev@sutransdev:~/webdocpy$ python manage.py inspectdb --database=eposse
...
from __future__ import unicode_literals

from django.db import models



inspectdb not identify the tables in the database and does not generate the model classes


The question is?

1) Am I doing something wrong. Currently there any way he could get Django to recognize a schema different from the "public" database schema? 

2) This is really a bug, and I need to create a ticket for this? 

3) or Django does not currently support different database schema, but this feature will be added when Marc Tamlyn add enhanced features to postgresql, as described here:



Thanks for the hard work to maintain this great framework



--
Fábio C. Barrionuevo da Luz
Acadêmico de Sistemas de Informação na Faculdade Católica do Tocantins - FACTO
Palmas - Tocantins - Brasil - América do Sul

Russell Keith-Magee

unread,
May 19, 2014, 8:53:35 PM5/19/14
to Django Developers
On Tue, May 20, 2014 at 5:38 AM, Fabio C. Barrionuevo da Luz <bna...@gmail.com> wrote:
Hello Django core developers.
Sorry if this is not the correct place to handle this.

Not really - this mailing list is for discussing the development of Django itself, not for solving usage questions. 
Well, there's *something* going wrong. inspectdb definitely works if you point it at a PostgreSQL database. I can only assume that either:

 a) The "neweposse" and "eposse" databases are actually empty, and don't actually contain schema, or 

 b) An error is being raised when connecting to the database, which is being silenced incorrectly

If (b) is happening, that would be a bug; you can check if this is the case by running "manage.py dbshell"; if you can't connect a shell to the database, inspectdb won't work either. If dbshell *does* work, then you can run /dt to confirm that tables actually exist in the database.
 
3) or Django does not currently support different database schema, but this feature will be added when Marc Tamlyn add enhanced features to postgresql, as described here:


AFAIK, nothing Marc is doing will change inspectdb functionality. 

Yours,
Russ Magee %-)

Tomek Paczkowski

unread,
May 20, 2014, 4:55:05 AM5/20/14
to django-d...@googlegroups.com
If I understand correctly, your legacy database is not in "public" schema.
Django offers no support for Postgres schemas, it's left to the developer/ops people to have correct search_path set.
There are two possible fixes for you:
- set Postgres user default search path to contain your schema
- hook into connection_created signal and set search pach manually[1]

[1]: https://docs.djangoproject.com/en/dev/ref/signals/#connection-created

Fabio Caritas Barrionuevo da Luz

unread,
May 21, 2014, 1:33:08 PM5/21/14
to django-d...@googlegroups.com
Tomek, is exactly that.

Russell, results of my tests inside dbshell:


the database that example I used is attached.

inspectdb realy dont work with postgresql schema

I opened the new ticket to handle this: https://code.djangoproject.com/ticket/22673

pulls_non-public_schema.backup
Reply all
Reply to author
Forward
0 new messages