#23153: 1.7 migrations' temporary tables cause problems with gis
---------------------------------+--------------------------------------
     Reporter:  TomLottermann    |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  GIS              |                  Version:  1.7-rc-2
     Severity:  Normal           |               Resolution:
     Keywords:  migrations, gis  |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------

Comment (by TomLottermann):

 I now was able to reconstruct this error in a smaller sample.
 My project is structured in the following way: projectfolder "gistest"
 with app "sample"
 My settings.py looks like this:

 {{{
 """
 Django settings for gistest project.

 For more information on this file, see
 https://docs.djangoproject.com/en/dev/topics/settings/

 For the full list of settings and their values, see
 https://docs.djangoproject.com/en/dev/ref/settings/
 """

 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 import os
 BASE_DIR = os.path.dirname(os.path.dirname(__file__))


 # Quick-start development settings - unsuitable for production
 # See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/

 # SECURITY WARNING: keep the secret key used in production secret!
 SECRET_KEY = 'k+=9bmpz)2+3v9(&+e6#x+iuqk!bz@g2!vl+fc7x$2blan+r9j'

 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True

 TEMPLATE_DEBUG = True

 ALLOWED_HOSTS = []


 # Application definition

 INSTALLED_APPS = (
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'django.contrib.gis',
     'gistest.sample',
 )

 MIDDLEWARE_CLASSES = (
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
 )

 ROOT_URLCONF = 'gistest.urls'

 WSGI_APPLICATION = 'gistest.wsgi.application'


 # Database
 # https://docs.djangoproject.com/en/dev/ref/settings/#databases

 DATABASES = {
     'default': {
         'ENGINE' : 'django.contrib.gis.db.backends.spatialite',
         'NAME'   : 'gistest.db',
         'TEST': {
             'NAME'    : '/path/to/test.db',
         }
     }
 }

 # Internationalization
 # https://docs.djangoproject.com/en/dev/topics/i18n/

 LANGUAGE_CODE = 'en-us'

 TIME_ZONE = 'UTC'

 USE_I18N = True

 USE_L10N = True

 USE_TZ = True


 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/dev/howto/static-files/

 STATIC_URL = '/static/'

 }}}

 My sample/models.py:

 {{{
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-

 from django.db import models
 from django.utils.translation import ugettext_lazy as _

 from django.contrib.gis.db import models as gis_models

 class Target(models.Model):
     pass

 class Location(models.Model):
     """
     Represents a named location.
     """

     objects = gis_models.GeoManager()

     name = models.TextField(verbose_name=_(u'name'))

     position = gis_models.PointField(verbose_name=_(u'position'))

     fk = models.ForeignKey(Target, blank=True, null=True)

     def __unicode__(self):
         return self.name

 }}}

 My sample/tests.py:

 {{{
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-

 from django.test import TestCase

 from django.contrib.auth.models import User

 from gistest.sample.models import Location

 class LocationTestCase(TestCase):
     def test_location(self):
         location = Location.objects.create(
             name="name",
             position='POINT(1 1)'
         )

 }}}

 Now after having created the initial migrations, executing manage.py test
 throws this exception:

 {{{
 ======================================================================
 ERROR: test_location (gistest.sample.tests.LocationTestCase)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 
"/home/thomas/Dokumente/Softwareprojekte/boozter/django17gistest/gistest/gistest/sample/tests.py",
 line 14, in test_location
     position='POINT(1 1)'
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/manager.py", line 92, in manager_method
     return getattr(self.get_queryset(), name)(*args, **kwargs)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/query.py", line 370, in create
     obj.save(force_insert=True, using=self.db)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/base.py", line 590, in save
     force_update=force_update, update_fields=update_fields)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/base.py", line 618, in save_base
     updated = self._save_table(raw, cls, force_insert, force_update,
 using, update_fields)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/base.py", line 701, in _save_table
     update_pk = bool(meta.has_auto_field and not pk_set)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/base.py", line 735, in _do_insert
     using=using, raw=raw)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/manager.py", line 92, in manager_method
     return getattr(self.get_queryset(), name)(*args, **kwargs)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/query.py", line 920, in _insert
     return query.get_compiler(using=using).execute_sql(return_id)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/models/sql/compiler.py", line 919, in execute_sql
     cursor.execute(sql, params)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/backends/utils.py", line 65, in execute
     return self.cursor.execute(sql, params)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/utils.py", line 94, in __exit__
     six.reraise(dj_exc_type, dj_exc_value, traceback)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/backends/utils.py", line 65, in execute
     return self.cursor.execute(sql, params)
   File
 "/home/thomas/Dokumente/Softwareprojekte/boozter/ENV/local/lib/python2.7
 /site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
     return Database.Cursor.execute(self, query, params)
 OperationalError: no such table: main.idx_sample_location__new_position
 }}}

 I believe that this comes from the fact, that alter_db_table (from
 contrib/gis/db/backends/sqlite/schema.py) is executed, which just renames
 the index table. I can imagine, that spatialite does not update the
 necessary references and therefore comes up with this error, when trying
 to insert something to the model table.

 Instead one could execute remove_geometry_metadata() before renaming the
 actual model table and execute part of column_sql() in order to create it
 again.

 Does anybody have any input on that idea?

 I stumbled across #23030 which might have had similar reasons.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/23153#comment:2>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.2f65c31e688a405ab98a0d920b02d210%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to