#10881: db.backends.postgresql.operations.sequence_reset_sql and M2M fields with non-integer PKs ---------------------------------------------------------------+------------ Reporter: gordyt | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: 1.0 Keywords: postgresql,operations,sequence_reset_sql,loaddata | Stage: Unreviewed Has_patch: 0 | ---------------------------------------------------------------+------------ Near the end of the command `python manage.py loaddata ...` the `sequence_reset_sql` is called. This part of the method is run for models that contain many-to-many fields: {{{ for f in model._meta.many_to_many: output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ (style.SQL_KEYWORD('SELECT'), style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())), style.SQL_FIELD(qn('id')), style.SQL_FIELD(qn('id')), style.SQL_KEYWORD('IS NOT'), style.SQL_KEYWORD('FROM'), style.SQL_TABLE(qn(f.m2m_db_table())))) }}}
Under normal circumstances this is fine. But if you are using your own model to manage the M2M relationship (specified via the `through=xxx` parameter in the `ManyToManyField`) and that model uses a non-integer primary key, then this part of the method generates invalid SQL code. I have attached two files to this ticket. The `models.py` file has additional comments at the top that shows the output of running the `loaddata` command. It is self-contained except that is uses the UUIDField from the django-extensions project. This version of a UUIDField is a simple `CharField` extension. The file `strtest_dump.json` is a very small file created by the `dumpdata` command. It has data for 3 authors and 1 book and the entries to join them together. -- Ticket URL: <http://code.djangoproject.com/ticket/10881> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---