[Django]-Django + Postgres: How to specify sequence for a field

2👍

I don’t think so, but there is a ticket open for that (with a possibly useful patch?):

http://code.djangoproject.com/ticket/1946

Edit:

Actually, that link above has a comment from HM on the thread with a better solution than the patch itself. The patch is old, I’m unsure if it will be applicable to the version of Django you are using.

1👍

What about this patch in Django: http://code.djangoproject.com/ticket/8901 ? And do you realy need the name of the sequence? As of version 8.2, PostgreSQL has RETURNING that you can use in INSERT’s (and UPDATE and DELETE) that can be used to get the created id:

INSERT INTO foo(bar) VALUES('John') RETURNING id;

I have no idea if Django can handle this (fetching an INSERT-result), but it’s a nice thing and also good for performance.

Leave a comment