On Mar 24, 10:00 pm, EAMiller <[email protected]> wrote:
> er-ca=# select pg_get_serial_sequence('er_utility', 'id');
>  pg_get_serial_sequence
> ------------------------
>
> (1 row)

Ok, I think I know what is going on in here. For some reason (most
likely this is a hand made schema) the sequence which is used as the
default value of er_utility's id column is not owned by that column.
Hence pg_get_serial_sequence will return null, and this results in
currval(pg_get_serial_sequence('er_utility', 'id')) to return null.
This all is defined in django/db/backends/postgresql/operations.py:

def last_insert_id(self, cursor, table_name, pk_name):
        # Use pg_get_serial_sequence to get the underlying sequence
name
        # from the table name and column name (available since
PostgreSQL 8)
        cursor.execute("SELECT
CURRVAL(pg_get_serial_sequence('%s','%s'))" % (
            self.quote_name(table_name), pk_name))
        return cursor.fetchone()[0]

Now, to fix this, first find out which sequence is used by
er_utility's id column (\d er_utility will help here). Then issue:

ALTER SEQUENCE seq_name OWNED BY er_utility, id;

Now everything should work as expected. If the same sequence is used
by multiple tables, there is unfortunately nothing you can do. A
sequence can be owned by only one column.

I will create a ticket about this problem.

 - Anssi

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

Reply via email to