GeoDjango--no "django_session_id_seq" with pgsql?

26 views
Skip to first unread message

Matthew Wensin

unread,
Oct 26, 2007, 1:51:08 PM10/26/07
to django-d...@googlegroups.com
I’m trying to use db_dump.py to migrate a geospatial db from one machine to another, and I’m getting the following error:

“Programming Error: relation ‘django_session_id_seq’ does not exist”

I’ve checked both databases and this sequence is no where to be found.  Is there an error somewhere in GeoDjango such that this isn’t being created?

Matt

Justin Bronn

unread,
Oct 26, 2007, 2:49:37 PM10/26/07
to Django developers
Matt,

First, a question of this sort is better suited to django-users, as
django-dev django-dev is for discussion of the development of Django
itself.

Second, from what I can tell db_dump.py is not part of the official
trunk -- thus I'm not familiar with it. My priority is to have
compatibility with the features already within Django before I worry
about third-party scripts.

Finally, `django_session_id_seq` tells me that the error is related to
the sessions framework, django.contrib.sessions (which is included in
INSTALLED_APPS by default). In the code for the Session model, the
primary key is manually specified for the `session_key` field --
therefore no AutoField is created for the Session model. My guess is
the bug lies with the script's handling of models that use primary
keys outside the implicit AutoField -- most likely this is not related
to GeoDjango.

-Justin

Matthew Wensin

unread,
Oct 26, 2007, 3:34:02 PM10/26/07
to django-d...@googlegroups.com
I suspected the script as well, but when I first asked the question in
#django, I was told by a pretty experienced Djangonista that the
"django_session_iq_seq" sequence should exist. As such I assumed it was a
problem with GeoDj.

Thanks for clearing this up,

Matt

limodou

unread,
Oct 26, 2007, 9:43:45 PM10/26/07
to django-d...@googlegroups.com
On 10/27/07, Matthew Wensin <mwen...@pbpost.com> wrote:
>
> I suspected the script as well, but when I first asked the question in
> #django, I was told by a pretty experienced Djangonista that the
> "django_session_iq_seq" sequence should exist. As such I assumed it was a
> problem with GeoDj.
>
> Thanks for clearing this up,
>
I never used PostgreSQL, and Eric SIMORRE has send me a patch about how to
reset the sequence field of PostgreSQL, and the function is:

def setSequence(cursor, model):
from django.conf import settings

# postgresql: reset sequence
if settings.DATABASE_ENGINE in ('postgresql_psycopg2', 'postgresql'):
cursor.execute('SELECT count(*) + 1 FROM %s;' %
quote_name(model._meta.db_table))
nb = cursor.fetchall()[0][0]

seq = quote_name(model._meta.db_table + '_id_seq')
cursor.execute('ALTER SEQUENCE %s RESTART WITH %d;' % (seq, nb))

So I think maybe this function makes the bug, and can someone help me to fix it?

--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou

oyvind....@gmail.com

unread,
Oct 26, 2007, 10:48:03 PM10/26/07
to Django developers
def setSequence(cursor, model):
from django.conf import settings

# postgresql: reset sequence
if settings.DATABASE_ENGINE in ('postgresql_psycopg2',
'postgresql'):

try:
f = model._meta.get_field('id')
except FieldDoesNotExist:
f = None
if f and isinstance(f, models.AutoField):


cursor.execute('SELECT count(*) + 1 FROM %s;' %
quote_name(model._meta.db_table))
nb = cursor.fetchall()[0][0]

seq = quote_name(model._meta.db_table + '_id_seq')
cursor.execute('ALTER SEQUENCE %s RESTART WITH %d;' % (seq,
nb))

this should work i think


On Oct 27, 3:43 am, limodou <limo...@gmail.com> wrote:

limodou

unread,
Oct 27, 2007, 12:32:32 AM10/27/07
to django-d...@googlegroups.com
On 10/27/07, oyvind....@gmail.com <oyvind....@gmail.com> wrote:
>
> def setSequence(cursor, model):
> from django.conf import settings
>
> # postgresql: reset sequence
> if settings.DATABASE_ENGINE in ('postgresql_psycopg2',
> 'postgresql'):
> try:
> f = model._meta.get_field('id')
> except FieldDoesNotExist:
> f = None
> if f and isinstance(f, models.AutoField):
> cursor.execute('SELECT count(*) + 1 FROM %s;' %
> quote_name(model._meta.db_table))
> nb = cursor.fetchall()[0][0]
>
> seq = quote_name(model._meta.db_table + '_id_seq')
> cursor.execute('ALTER SEQUENCE %s RESTART WITH %d;' % (seq,
> nb))
>
> this should work i think
>
Thanks a lot. I'v update the svn http://code.google.com/p/db-dump/,
but I haven't tested it, so maybe Matthew can help me to test it.

limodou

unread,
Oct 27, 2007, 9:51:07 AM10/27/07
to django-d...@googlegroups.com
You can read this thread, and someone given a patch, you can test it.
The newest code is in the svn.
Reply all
Reply to author
Forward
0 new messages