{{{
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.
Comment (by Simon Charette):
Hello Kaveh,
Did you reproduce against 1.11 as well? Would it be possible for you to
provide the full traceback of the `AttributeError`?
--
Ticket URL: <https://code.djangoproject.com/ticket/28499#comment:1>
Comment (by Kaveh):
Hi Simon, I just tried with Django 1.11 and everything works fine there.
Unfortunately I'm stuck with Django 1.8.14 right now and upgrade is not an
option for me.
Here's the full traceback:
{{{
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 354, in
execute_from_command_line
utility.execute()
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/core/management/base.py", line 444, in execute
self.check()
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/core/management/base.py", line 482, in check
include_deployment_checks=include_deployment_checks,
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/core/checks/model_checks.py", line 28, in check_all_models
errors.extend(model.check(**kwargs))
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/db/models/base.py", line 1205, in check
errors.extend(cls._check_fields(**kwargs))
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/db/models/base.py", line 1282, in _check_fields
errors.extend(field.check(**kwargs))
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 207, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/db/models/fields/__init__.py", line 306, in
_check_backend_specific_checks
return connection.validation.check_field(self, **kwargs)
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/db/backends/mysql/validation.py", line 18, in check_field
field_type = field.db_type(connection)
File "/home/user/sandbox/venv/local/lib/python2.7/site-
packages/django/contrib/gis/db/models/fields.py", line 247, in db_type
return connection.ops.geo_db_type(self)
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
}}}
Replying to [comment:1 Simon Charette]:
> Hello Kaveh,
>
> Did you reproduce against 1.11 as well? Would it be possible for you to
provide the full traceback of the `AttributeError`?
--
Ticket URL: <https://code.djangoproject.com/ticket/28499#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
Per our [https://docs.djangoproject.com/en/dev/internals/release-process
/#supported-versions supported versions policy], 1.8 is only receiving
security and data loss fixes so we can close this. Thanks for checking.
--
Ticket URL: <https://code.djangoproject.com/ticket/28499#comment:3>