[Django] #28499: makemigrations fails on model with geometry field when the geo database is not the defaul one

3 views
Skip to first unread message

Django

unread,
Aug 15, 2017, 7:32:09 PM8/15/17
to django-...@googlegroups.com
#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.

Django

unread,
Aug 15, 2017, 8:56:00 PM8/15/17
to django-...@googlegroups.com
#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 | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+--------------------------------------

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>

Django

unread,
Aug 16, 2017, 12:16:44 PM8/16/17
to django-...@googlegroups.com
#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 | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+--------------------------------------

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>

Django

unread,
Aug 16, 2017, 12:27:20 PM8/16/17
to django-...@googlegroups.com
#28499: makemigrations fails on model with geometry field when the geo database is
not the default one
------------------------+--------------------------------------
Reporter: Kaveh | Owner: nobody
Type: Bug | Status: closed
Component: GIS | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+--------------------------------------
Changes (by Tim Graham):

* 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>

Reply all
Reply to author
Forward
0 new messages