The client's manual insertion of table id numbers, which was necessary
to make the admin panel work with the table ids set to IntegerField in
models.py, caused the sequence behind the serial field to go out of
whack in postgres. This had to be fixed in postgres.

SELECT SETVAL ('primary_key_seq', 35)

Where primary_key_seq was the returned value of SELECT
pg_get_serial_sequence(), and '35' was a number greater than any value
already in the primary key column a little extra for safety.

The moral of the story is don't accept the default behavior of
manage.py inspectdb regarding this matter. Change primary keys set to
IntegerField to AutoField before deployment. If the column is actually
called "id" (as opposed to "blog_id", for instance), I believe that
you can get away with deleting the line completely from the models.

Cheers!

Franklin



On Sun, Jul 18, 2010 at 9:07 AM, franklin <franklin.einspr...@gmail.com> wrote:
> Greetings,
>
> I created the models in a Django app using manage.py inspectdb on an
> existing postgres database. This seemed to work except that all the
> primary keys were described in the models as IntegerFields, which made
> them editable in the admin panel, and had to be hand-entered based on
> knowledge of the id of the previous record. I just learned about this
> after some usage by the client, so I went back to change things like
>
> artist_id = models.IntegerField(primary_key=True)
>
> ...to...
>
> artist_id = models.AutoField(primary_key=True)
>
> Now the id fields don't appear in the admin panel, but adding new rows
> has become impossible.
>
>> IntegrityError at /admin/franklins_app/blog/add/
>> duplicate key value violates unique constraint "blog_pkey"
>
> I've checked the tables and there don't seem to be insane entries in
> primary key columns. I've tried commenting the aforementioned lines
> out of the models completely and I get the same error. Does anyone
> know the fix here? Thanks for the help.
>
> Franklin
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
Art, writing, journal: http://einspruch.com
Comics: http://themoonfellonme.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to