IntegrityErrors after Postgres database restore attempt

179 views
Skip to first unread message

Jason

unread,
Dec 31, 2009, 2:19:20 AM12/31/09
to Django users
Hi folks--

I recently hosed my django database, & attempted to do a restore using
Navicat for Postgresql. Seems like this was not the thing to try, as
django now throws these:

IntegrityError: duplicate key violates unique constraint
"django_content_type_pkey" (for instance, after adding a new app &
running syncdb)

...anytime I try to add a row to many of the tables (but seemingly not
all) which were restored in that fashion.

I managed to get the auth_* tables back up to snuff simply by running
"manage.py reset auth", then manually re-entering the data (luckily
there weren't many items).

The big problem now, as you can see from the above error, is that if I
try to add a new app, it squawks presumably because it's trying to
assign an already existing pkey to django_content_type. The
sequencereset command looked promising, but that applies to apps
only-- resetting the django_content_type table is what I guess I need
to do...?

Was thinking of trying dumping the data & running a syncdb-- but I
don't know if the django_* tables are necessarily going to be
recreated correctly simply by doing that.

Hope I'm being clear, & any advice much appreciated!

Felipe Reyes

unread,
Dec 31, 2009, 8:39:11 AM12/31/09
to django...@googlegroups.com
Hi

2009/12/31 Jason <elgrand...@gmail.com>:

> The big problem now, as you can see from the above error, is that if I
> try to add a new app, it squawks presumably because it's trying to
> assign an already existing pkey to django_content_type.  The
> sequencereset command looked promising, but that applies to apps
> only-- resetting the django_content_type table is what I guess I need
> to do...?

You should check the current value for the sequences, and update them
to highest value used on your table
http://www.postgresql.org/docs/current/interactive/functions-sequence.html

Probably the next value in the sequence is X, but X is already being
used by some row, so that violates the primary key.

Regards,

Reply all
Reply to author
Forward
0 new messages