#28499: makemigrations fails on model with geometry field when the geo database 
is
not the defaul one
--------------------------------------+------------------------
               Reporter:  Kaveh       |          Owner:  nobody
                   Type:  Bug         |         Status:  new
              Component:  GIS         |        Version:  1.8
               Severity:  Normal      |       Keywords:
           Triage Stage:  Unreviewed  |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  0
                  UI/UX:  0           |
--------------------------------------+------------------------
 Create a django app with two databases defined like this:

 {{{
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.mysql',
         'NAME': 'whatever'
         ...
     },
     'postgres': {
         'ENGINE': 'django.contrib.gis.db.backends.postgis',
         'NAME': 'whatever'
     }
 }
 }}}

 and here is the database router:

 {{{
 POSTGRES_APPS = ['app1']


 class PostgresRouter(object):
     def db_for_read(self, model, **hints):
         if model._meta.app_label in POSTGRES_APPS:
             return 'postgres'
         return None

     def db_for_write(self, model, **hints):
         if model._meta.app_label in POSTGRES_APPS:
             return 'postgres'
         return None

     def allow_relation(self, obj1, obj2, **hints):
         if {obj1._meta.app_label,
 obj2._meta.app_label}.issubset(set(POSTGRES_APPS)):
             return True
         return None

     def allow_migrate(self, db, app_label, model_name=None, **hints):
         if db == 'postgres':
             return app_label in POSTGRES_APPS
         else:
             return app_label not in POSTGRES_APPS
 }}}

 Create an app called `app1` and add it to `INSTALLED_APPS`:

 {{{
 class Shapes(models.Model):
     shape = models.GeometryField()
 }}}

 Now if you run `makemigrations`, it throws the following error:
 `AttributeError: 'DatabaseOperations' object has no attribute
 'geo_db_type'`

 Seems like the error is because Django is using the default connection,
 i.e. mysql, for handling the geomtry field in app1, though this app is
 supposed to be part of the gis enabled database, i.e. postgres.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28499>
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/048.3661aad8c8937fbcc94e0c8c3a98812b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to