Postgres sequences without the 'owned by' attribute do not return id in Django 1.3

After a recent migration from Oracle to Postgres and upgrading from Django 1.2 to 1.3, we had problems saving objects to our database. When the save () function is called, no id is returned, this happens even when standard django auth models are saved through the standard django admin panel (returns '/ admin / auth / user / None /' even if the user was added to db and had an identifier) .

All our other sites that run the same db do not have this problem, however they run Django 1.1 or 1.2.

We found that for new tables created after migration, their sequence had an β€œbelongs” attribute that belonged to the column in which this sequence was included (usually this is an identifier column). Changing the "belonged" attribute fixed the problems that we had in version 1.3.

Does anyone know what is the reason behind this? We found a solution if anyone else has this problem, but we would like to know what caused it.

+7
django postgresql
source share
2 answers

In postgresql, if you have an object, you can effectively do whatever you want with it. As a result, if you are not the owner, you need to provide the user with "USE" in sequence.

Postgresql Property Rights

Grants Postgresql

+6
source share

It seems that django probably uses pg_get_serial_sequence to get the sequence associated with the table column, and then currval to get the current value of the sequence, but if the sequence does not belong to the table, it is not connected to the column, so it will not work.

The OWNED BY attribute associates a sequence with a given table and column. If a sequence has OWNED BY set to NULL , it is essentially an autonomous sequence and is not connected in any way to any table or column and is even less related to the primary key.

+1
source share

All Articles