dumpdata/loaddata fails with many-to-many tables on postgresql
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Severity:||Keywords:||manage.py loaddata dumpdata postgresql|
|Cc:||gary.wilson@…, real.human@…, arthur.case@…, tom@…, mark@…, portland@…, floguy@…, django@…, remco@…, eliott@…, pythonmailing@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I did a (manage.py) dumpdata then loaddata with some models that had many to many fields. The subsequent loaddata operation failed with an error:
psycopg2.ProgrammingError: relation "keywordsites_site__site__keywords" does not exist.
The problem is that the name of the table is reduced to lower case where the name of the table is actually has an uppercase S
and further investigation revealed that the generated SQL had the correct capitalisation but the table name was not quoted - hence the problem.
The fix is to change line 96 on django/db/backends/postgresql/operations.py to:
output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s \"%s\";" % \
No idea how to make a .diff, sorry, but for a single line I'm sure you can cope. It would be nice to be able to turn WikiFormatting off inline too.
Change History (5)
comment:1 Changed 9 years ago by
|Cc:||gary.wilson@… real.human@… arthur.case@… tom@… mark@… portland@… floguy@… django@… remco@… eliott@… pythonmailing@… added|
|Patch needs improvement:||unset|