Trouble with Django 1.7 migrate, duplicate add_postgisgeometrycolumns key error.

952 views
Skip to first unread message

Andrew Cordery

unread,
Sep 17, 2014, 2:51:26 PM9/17/14
to geod...@googlegroups.com
I've just upgraded to Django 1.7 and so far everything is going swimmingly, with the exception that every single time I run migrate, it attempts to add the 'add_postgisgeometrycolumns' permission to the database, which causes an IntegrityError since it already exists.  This error also occurs with the --no-initial-data flag as well.  The migration was initally run with --fake and completed succesfully, but every subsequent migrate command (even when nothing has changed, so it would be a migrate that should produce no results) raises the same error.  

As far as I can see the only place this would be coming from is django.contrib.gis.   I'm sure this is just some silly error, probably on my part, but I can't figure it out.  Any ideas?




python manage.py migrate
/app/.heroku/src/languages-plus/languages_plus/models.py:123: RemovedInDjango18Warning: `CultureCodeManager.get_query_set` method should be renamed `get_queryset`.
  class CultureCodeManager(models.Manager, CultureCodeMixin):

System check identified some issues:

WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
        HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & beha
Operations to perform:
  Synchronize unmigrated apps: grappelli, reversion, storages, cacheops, compressor, raven_compat, djrill, crispy_forms, django_extensions, clear_cache, debug_toolbar, countries_plus,
analytical, django_reset, customer_portal, adv_cache_tag, djangobower, control_panel, collectfast, rosetta, modeltranslation, djangosecure, callingrates, autoslug, gis, customers, curr
encies, languages_plus
  Apply all migrations: auth, pickup_locations, smartystreets, us_hotels, geonames_cities, carts, sales_tax, vendors, pricing, core, contenttypes, notifications, admin, orders, session
s
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Installed 252 object(s) from 1 fixture(s)
Installed 419 object(s) from 1 fixture(s)
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 164, in handle
    emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/sql.py", line 268, in emit_post_migrate_signal
    using=db)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 198, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 114, in create_permissions
    Permission.objects.using(using).bulk_create(perms)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 409, in bulk_create
    self._batched_insert(objs_without_pk, fields, batch_size)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 938, in _batched_insert
    using=self.db)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 921, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "auth_permission_content_type_id_codename_key"
DETAIL:  Key (content_type_id, codename)=(50, add_postgisgeometrycolumns) already exists.

Claude Paroz

unread,
Sep 18, 2014, 3:42:54 AM9/18/14
to geod...@googlegroups.com
Hi Andrew,

The traceback shows that something is going astray during the check
about which permissions are missing and should be added, in
contrib.auth.
https://github.com/django/django/blob/master/django/contrib/auth/management/__init__.py#L61

Basically, this function computes all needed permissions, then queries
the existing permissions, makes the diff "needed - existing" and creates
the missing ones.
I would place a break point (if app_config.label == 'gis': import pdb;
pdb.set_trace()) in this function and try to understand why the missing
perms (`perms` variable) is not empty.

Hopefully this will give you a hint about what's going wrong.

Claude
> --
> You received this message because you are subscribed to the Google
> Groups "geodjango" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to geodjango+...@googlegroups.com.
> To post to this group, send email to geod...@googlegroups.com.
> Visit this group at http://groups.google.com/group/geodjango.
> For more options, visit https://groups.google.com/d/optout.

--
www.2xlibre.net

micha...@gmail.com

unread,
Oct 12, 2014, 1:53:21 PM10/12/14
to geod...@googlegroups.com
Hey Andrew,

did you find the source of the problem? Seems I've just hit the same, or at least very similar looking bug... 

ma...@twined.net

unread,
Nov 3, 2014, 7:46:52 AM11/3/14
to geod...@googlegroups.com
Hi, I found this post while googling for the error I got.

I did some heavy digging, but came up empty. The debugging made absolutely no sense at all, and at the end of it it suddenly worked.

Turns out I had cached the permissions table through cacheops.

Flushed the cache (./manage.py invalidate auth), removed the caching of auth.* from my cacheops settings and everything went back to normal.
Reply all
Reply to author
Forward
0 new messages